1、UIButton 同时添加图片和文字的时候,一般是图片在左,文字在右,稍微加些间距,就可以满足设计师们的要求;有些需求是文字在左,图片在右,这个时候其实我们也只需要把UIbutton的方向改变一下就可以了:
UIView.userInterfaceLayoutDirection(for: .unspecified) = .rightToLeft
在XIB中就是UIButton下面的关于的 UIVIew的 semantic 改为 force Right-to-Left
但是在Arabic时,会有问题,依然是right-to-left 这个时候,其实应该是 Left-to-Right ,所以我们需要对UIButton写一个 extension
如下:
@IBInspectable
var autoSemanticContentBoth: Bool {
get {
return false
}
set {
if newValue {
if UIView.userInterfaceLayoutDirection(for: .unspecified) == .rightToLeft {
semanticContentAttribute