:)
我有一个非常奇怪的问题。 我正在做的是使用customView作为UIButton创建一个UIBarButtonItem。 我的导航栏的高度大于默认值(80pt),而我试图垂直居中左侧和右侧。右栏按钮项,所以我将imageEdgeInsets提供给customView UIButton。 它看起来很棒,但只有一个奇怪的问题,RTL语言中的触摸区域是OFF(只有图片中的实际按钮区域),但在LTR中效果很好。
我的代码是:
let rightImageInsets = UIEdgeInsets(top: -24, left: 0, bottom: 24, right: -10)
let leftImageInsets = UIEdgeInsets(top: -24, left: -10, bottom: 24, right: 0)
var insets: UIEdgeInsets
if BSUtility.ios9AndRightToLeftUserInterface() {
if location == .RightButtonItem {
insets = leftImageInsets
} else {
insets = rightImageInsets
}
} else {
if location == .RightButtonItem {
insets = rightImageInsets
} else {
insets = leftImageInsets
}
}
let buttonImage = UIImage(named: "nav_back")!
let button = UIButton(type: .System)
button.tintColor = UIColor.blackColor()
button.addTarget(targetController, action: Selector(targetAction), forControlEvents: .TouchUpInside)
button.setImage(buttonImage, forState: .Normal)
button.sizeToFit()
button.imageEdgeInsets = insets
navigationItem.rightBarButtonItem = BarButtonItem(customView: button)
有什么建议吗?
非常感谢!! :)