我正在使用委托方法来设置FormData? optionalFormData
的标题并设置UIPickerView
的对齐方式。但是,如果我从英语切换到阿拉伯语,它是正确对齐的。如果在启动过程中使用的语言是阿拉伯语,则切换到英语后会向左对齐。
.center
答案 0 :(得分:1)
如果对组件使用RTL语言支持,则需要强制更新对齐方式。
func pickerView(_ pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusing view: UIView?) -> UIView {
var pickerLabel : UILabel
if let label = view as? UILabel {
pickerLabel = label
} else {
pickerLabel = UILabel()
pickerLabel.textColor = UIColor.black
if pickerLabel.effectiveUserInterfaceLayoutDirection == .rightToLeft {
pickerLabel.textAlignment = NSTextAlignment.center
}
}
pickerLabel.text = "10"
pickerLabel.sizeToFit()
return pickerLabel
}
答案 1 :(得分:0)
无需尝试就可以给UI标签框架尝试。仅给您选择器一个约束。
func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView!) -> UIView
{
var pickerLabel = UILabel()
pickerLabel.textColor = UIColor.blackColor()
pickerLabel.text = "PickerView Cell Title"
pickerLabel.font = UIFont.boldSystemFont(ofSize: 13)
pickerLabel.textAlignment = NSTextAlignment.Center
return pickerLabel
}