gpt4 book ai didi

ios - UIBarButtonItem 大小显示错误

转载 作者:行者123 更新时间:2023-11-30 11:17:57 25 4
gpt4 key购买 nike

我有自定义UINavigationBar(用于JSQMessagesViewController)和一些项目。但我对 leftBarButtonItem

有一些问题
func setNavigationBar() {
let screenSize: CGRect = UIScreen.main.bounds
let navBar = UINavigationBar(frame: CGRect(x: 0, y: 28, width: screenSize.width, height: 78))
let navItem = UINavigationItem(title: chatName ?? "chat")
let menuBtn = UIButton(type: .custom)
menuBtn.frame = CGRect(x: 0.0, y: 0.0, width: 78, height: 78)
menuBtn.setImage(UIImage(named: "backButton"), for: .normal)
menuBtn.addTarget(self, action: #selector(back), for: UIControl.Event.touchUpInside)

let menuBarItem = UIBarButtonItem(customView: menuBtn)
let currWidth = menuBarItem.customView?.widthAnchor.constraint(equalToConstant: 78)
currWidth?.isActive = true
let currHeight = menuBarItem.customView?.heightAnchor.constraint(equalToConstant: 78)
currHeight?.isActive = true
navItem.leftBarButtonItem = menuBarItem


navBar.titleTextAttributes = [.font : UIFont(name: "Acrom-Bold", size: 26)!, .foregroundColor : UIColor.white]
navBar.setItems([navItem], animated: false)
navBar.setBackgroundImage(UIImage(), for: .default)
navBar.shadowImage = UIImage()
navBar.backgroundColor = UIColor(displayP3Red: 0, green: 0, blue: 0, alpha: 0.3)
navBar.isTranslucent = true

self.view.addSubview(navBar)
}

但是我的后退按钮看起来不对。按钮的高度有什么问题? enter image description here

最佳答案

如果栏按钮项具有自定义 View ,则必须使用内部自动布局约束调整自定义 View 的宽度。

但是您不能将高度设置为大于运行时喜欢的高度,就像您所做的那样。删除这些行:

let currHeight = menuBarItem.customView?.heightAnchor.constraint(equalToConstant: 78)
currHeight?.isActive = true

关于ios - UIBarButtonItem 大小显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51583188/

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