我有一个UIView
,身高= 1.0,并附有一个使用Autolayout附加的选择器视图(它显示在视图下方)。
我的选择器视图的宽度应该与行分隔符(UIView)相等。
在iPhone上它运行良好,但在iPad上,选择器视图在中间切成薄片。 我在" Debug视图层次结构"中进行了测试,发现它实际上在视图的宽度上,但仍然在中间切割(参见截图)。
然后我认为这可能是委托功能问题,所以我添加了这些实现:
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
let rowInfo = getRowText(for: pickerView, fromRow: row, andComponent: component)
let field = (view as? UITextField) ?? UITextField()
field.font = font16
field.textAlignment = .left
field.textColor = .black
field.text = rowInfo.text
return field
}
func pickerView(_ pickerView: UIPickerView, widthForComponent component: Int) -> CGFloat {
return self.aSeperator.frame.width
}
答案 0 :(得分:1)
UIPickerView
上的viewDidLoad
调用此函数:
clientPickerView.roundCorners([.bottomLeft, .bottomRight], radius: 4.0)
clientSitePicker.roundCorners([.bottomLeft, .bottomRight], radius: 4.0)
此功能会更改选择器视图的遮罩,为其添加圆角(如上图所示):
func roundCorners(_ corners: UIRectCorner, radius: CGFloat) {
let path = UIBezierPath(roundedRect: self.bounds, byRoundingCorners: corners, cornerRadii: CGSize(width: radius, height: radius))
let mask = CAShapeLayer()
mask.path = path.cgPath
self.layer.mask = mask
}
解决方案是将此调用移至viewDidLayoutSubviews
。