【发布时间】:2026-01-07 14:25:03
【问题描述】:
我有一个在 iOS 14 上无法正确显示文本的pickerview。有人知道如何解决这个问题吗?好像有一个子视图覆盖了文本?
是因为我使用的是自定义标签吗?
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let pickerLabel = UILabel()
let titleData = pickerDataSource[row]
pickerView.subviews[1].backgroundColor = .clear
pickerView.subviews[0].backgroundColor = .clear
let myTitle = NSAttributedString(string: titleData, attributes: [NSAttributedString.Key.font:UIFont.systemFont(ofSize: 18),NSAttributedString.Key.foregroundColor:UIColor.black])
pickerLabel.attributedText = myTitle
return pickerLabel
}
【问题讨论】:
-
发布您的代码。
-
刚刚更新:)
-
使用 View Debugger 查看是否有东西覆盖了文本。
-
我正在经历完全相同的事情,只是使用了更简单的自定义标签。没有任何东西覆盖文本;您经常可以看到新的矩形区域包含第一个字符的几个像素。到目前为止,我发现的唯一解决方案是使用中心对齐。向 Apple 提交错误报告:feedbackassistant.apple.com
标签: ios swift uipickerview