我有一个迅速的应用程序,其中视图控制器嵌入导航控制器中,现在在第二和第三视图控制器的后退按钮上,有一个向后指向的蓝色箭头(默认情况下位于该位置)。我试图删除它,但是当我想要在其中放置图像时,图像将全部被压缩。有谁知道您将如何删除后退按钮箭头,然后将其替换为图像?
非常感谢!
最佳答案
用这个....
设置文本:
let backBtn = UIBarButtonItem(title: "Back", style: UIBarButtonItemStyle.Plain, target: self, action: "BtnTapBack:")
navigationItem.leftBarButtonItem = backBtn
navigationItem.leftBarButtonItem?.setTitleTextAttributes([NSFontAttributeName: UIFont(name: "YourFontName", size: 20)!], forState: UIControlState.Normal)
设置图像:
let image = UIImage(named:"YourImageName") as UIImage!
var btnBack:UIButton = UIButton.buttonWithType(UIButtonType.Custom) as! UIButton
btnBack.addTarget(self, action: "BtnTapBack:", forControlEvents: UIControlEvents.TouchUpInside)
btnBack.setImage(image, forState: UIControlState.Normal)
btnBack.setTitleColor(UIColor.blueColor(), forState: UIControlState.Normal)
btnBack.sizeToFit()
var myCustomBackButtonItem:UIBarButtonItem = UIBarButtonItem(customView: btnBack)
self.navigationItem.leftBarButtonItem = myCustomBackButtonItem
操作转到上一个视图控制器
@IBAction func BtnTapBack(sender: UIButton) {
navigationController?.popViewControllerAnimated(true)
}