![](/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.