问题描述:

I want to globally change the navigation bar back button, so I have this:

UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-100, -5000), forBarMetrics: .Default)

var backImage: UIImage = UIImage(named: "BackButton")!

backImage = backImage.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, 0, 0, 20))

UINavigationBar.appearance().backIndicatorImage = backImage

UINavigationBar.appearance().backIndicatorTransitionMaskImage = backImage

But the back image is too close to the left of the screen. How do I move it farther to the right?

网友答案:

Just adjust the actual image.

extension UIImage {
    func imageWithInsets(insets: UIEdgeInsets) -> UIImage {
        UIGraphicsBeginImageContextWithOptions(
        CGSizeMake(self.size.width + insets.left + insets.right,
                self.size.height + insets.top + insets.bottom), false, self.scale)
        let context = UIGraphicsGetCurrentContext()
        let origin = CGPoint(x: insets.left, y: insets.top)
        self.drawAtPoint(origin)
        let imageWithInsets = UIGraphicsGetImageFromCurrentImageContext()
        UIGraphicsEndImageContext()
        return imageWithInsets
    }
}
网友答案:

You need to adjust the left position on UIEdgeInsetsMake.

You are already calling it here:

backImage = backImage.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, 0, 0, 20))

Like so:

backImage = backImage.imageWithAlignmentRectInsets(UIEdgeInsetsMake(0, -50, 0, 50))
相关阅读:
Top