我正在对阿拉伯语进行本地化,其中我必须从右向左书写文本。 不,我不会使用POD或Bundle。我在运行时使用CountryPicker选择国家/地区。
对于标签,我确实使用了下面的有效代码
self.userNameLbl.textAlignment = .right
我已经用过
UITextField.appearance().semanticContentAttribute = .forceRightToLeft
还是没用
答案 0 :(得分:1)
我对您要更改文本字段或标签的对齐方式的问题感到有些困惑,但是对于文本字段,我使用了它,并且它的工作原理是您必须首先为textfild创建出口或将其定义为变量
NameTextField.textAlignment = .right
答案 1 :(得分:0)
您可以这样做:
label.textAlignment = NSTextAlignment.center;
或者,简写为:
label.textAlignment = .center;
雨燕3
label.textAlignment = .center
或
您可以使用属性字符串设置占位符文本。通过属性传递所需的颜色:
var myTextField = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 30))
myTextField.backgroundColor = .blue
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSForegroundColorAttributeName: UIColor.yellow])
对于Swift 3+,请使用以下命令:
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSAttributedStringKey.foregroundColor: UIColor.white])
对于Swift 4.2,请使用以下代码:
myTextField.attributedPlaceholder = NSAttributedString(string: "placeholder text",
attributes: [NSAttributedString.Key.foregroundColor: UIColor.white])
答案 2 :(得分:-1)
go to storyboard -> select your textfield -> attributes inspector -> view -> semantic set to forceRightToLeft.