后退按钮显示图像痕迹

时间:2016-10-30 10:33:52

标签: ios swift3

let backImage:UIImage = (UIImage.init(named: "Back-btn")?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 30, 0, 0)))!
UIBarButtonItem.appearance().setBackButtonBackgroundImage(backImage, for: .normal, barMetrics: .default)
UIBarButtonItem.appearance().setBackButtonTitlePositionAdjustment(UIOffsetMake(-60, -60),for:.default)

我想在应用开始时在appdelegate.swift中定义后退按钮的外观。而且我也不需要后退按钮的标题。 我想在后退按钮中删除这些痕迹。

上面的代码显示了一个Back按钮,如下图所示: enter image description here

1 个答案:

答案 0 :(得分:2)

替换

let backImage:UIImage = (UIImage.init(named: "Back-btn")?.resizableImage(withCapInsets: UIEdgeInsetsMake(0, 30, 0, 0)))!

let backImage: UIImage = UIImage(named: "Back-btn")!.stretchableImage(withLeftCapWidth: widthOfTheBackButtonImage, topCapHeight: 0)

其中widthOfTheBackButtonImage是图像的宽度。您还必须确保图像右侧至少有1个透明点。