iOS 14/Xcode 12.0.1 更新后 UIPickerView 渲染不正确 [英] UIPickerView rendering incorrectly after iOS 14/Xcode 12.0.1 update

查看:35
本文介绍了iOS 14/Xcode 12.0.1 更新后 UIPickerView 渲染不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人注意到您的应用程序的 UIPickerViews 中的文本呈现错误,第一个字符被截断了吗?我在多个设备上的应用程序中的所有 UIPickerViews 中都看到了这一点.大多数情况下,您可以看到第一个字符的几个像素.

Anybody notice that the text in your application's UIPickerViews is rendered incorrectly, with the first character cut off? I'm seeing this in all UIPickerViews in my app, on multiple devices. You can see a few pixels of the first character in most cases.

我尝试从手机中删除派生数据和应用程序,但没有删除.

I've tried deleting derived data, and the application from the phones, but no dice.

我不确定哪个更新可能触发了这个问题,但它只是在一个已经稳定了几个月的项目中开始的.标签代码:

I'm not sure which update might have triggered the problem, but it just started in a project that has been stable for months. The code for the labels:

func pickerView(_ pickerView: UIPickerView,
                viewForRow row: Int,
                forComponent component: Int,
                reusing view: UIView?) -> UIView
{
    let pickerLabel = UILabel()
    pickerLabel.text = "Rec.709"
    pickerLabel.font = UIFont(name: "Ropa Sans", size: 18)
    pickerLabel.textColor = UIColor.white
    pickerLabel.textAlignment = NSTextAlignment.left
}

推荐答案

没有对我的 PickerViews 进行任何更改,但是自从更新到 iOS 14 后我遇到了完全相同的问题.似乎 Apple 更改了 PickerView 实现中的某些内容.

Did not change anything to my PickerViews, but I am experiencing exactly the same problem since updating to iOS 14. Seems like Apple changed something in the PickerView implementation.

我的 ViewForRow 函数返回一个包含三个标签的水平 UIStackView.通过在第一个标签的前缘和最后一个标签的后缘添加 15 点偏移约束,我能够暂时解决该问题:

My ViewForRow function is returning a horizontal UIStackView containing three labels. I was able to solve the problem temporarily by adding a 15 points offset constraint to the leading edge of the first label, and the trailing edge of the last:

func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {

    var stackView: UIStackView

    if view != nil {
        stackView = view as! UIStackView
    } else {

        let leftLabel = UILabel()
        let ctrLabel = UILabel()
        let rightLabel = UILabel()

        stackView = UIStackView(arrangedSubviews:[leftLabel, ctrLabel, rightLabel])
        stackView.axis = .horizontal
        stackView.distribution = .fill

    // Temporary fix.
        leftLabel.leadingAnchor.constraint(equalTo: stackView.leadingAnchor, constant: 15.0).isActive = true
        rightLabel.trailingAnchor.constraint(equalTo: stackView.trailingAnchor, constant: -15.0).isActive = true

    // Set text of labels here...

    return stackView
}

我还不能检查,但我担心这个额外的余量现在在仍然运行旧 iOS 版本的设备上看起来很奇怪.

I haven't been able to check yet, but I am afraid that this extra margin may now look weird on devices that are still running an older iOS version.

这篇关于iOS 14/Xcode 12.0.1 更新后 UIPickerView 渲染不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆