gpt4 book ai didi

ios - 后退按钮左对齐 IOS 9

转载 作者:搜寻专家 更新时间:2023-10-31 22:06:39 27 4
gpt4 key购买 nike

我正在尝试左对齐后退按钮 删除后退箭头左侧的空格。使用自定义后退按钮。

let backButton = UIBarButtonItem(image: UIImage(named: "arrow03"), style: .Plain, target: self, action: "back")

self.navigationController?.navigationBar.tintColor = UIColor.clearColor()
self.navigationItem.backBarButtonItem = backButton

尝试按照以下 SO 链接中的建议对按钮使用负宽度,但没有成功。 How to Edit Empty Spaces of Left, Right UIBarButtonItem in UINavigationBar [iOS 7]

图片

enter image description here

http://imgur.com/PA9HLBm

请帮忙。

最佳答案

引用下面的代码实现左对齐的后退按钮。

let button: UIButton = UIButton (type: UIButtonType.Custom)
button.setImage(UIImage(named: "imageName"), forState: UIControlState.Normal)
button.addTarget(self, action: "backButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.frame = CGRectMake(0, 0, 30, 30)
let barButton = UIBarButtonItem(customView: button)

self.navigationItem.leftBarButtonItem = barButton

注意 - 确保您的图片必须是纯色(透明)背景。

func backButtonPressed(btn : UIButton) {

self.navigationController?.popViewControllerAnimated(true)
}

Swift 4 代码

override func viewDidLoad() {
super.viewDidLoad()

let button: UIButton = UIButton (type: UIButtonType.custom)
button.setImage(UIImage(named: "imageName"), for: UIControlState.normal)
button.addTarget(self, action: Selector(("backButtonPressed:")), for: UIControlEvents.touchUpInside)
button.frame = CGRect(x: 0 , y: 0, width: 30, height: 30)

let barButton = UIBarButtonItem(customView: button)

self.navigationItem.leftBarButtonItem = barButton
}

func backButtonPressed(btn : UIButton) {

self.navigationController?.popViewController(animated: true)
}

关于ios - 后退按钮左对齐 IOS 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36709220/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com