![](/img/trans.png)
[英]Setting UITableView and section direction/alignment to be RTL (Right to Left)
[英]UIButton title alignment not changing to right direction in RTL
接受的答案对我没有帮助。 但是以下代码段可以自动支持 RTL 和 LTR 语言:
// makes button content support RTL <-> LTR
button.contentHorizontalAlignment = .leading
// makes titleLabel support RTL <-> LTR
button.titleLabel?.textAlignment = .natural
不知道为什么会发生,但您必须继承 UIButton 以便您可以覆盖alignmentRectInsets
。
override func alignmentRectInsets() -> UIEdgeInsets {
var insets: UIEdgeInsets
if (Left_Side_Button) {
insets = UIEdgeInsetsMake(0, 7.0, 0, 0)
}
else {
// Right Button
insets = UIEdgeInsetsMake(0, 0, 0, 7.0)
}
return insets
}
并通过上述代码实现。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.