【发布时间】:2022-01-23 06:27:36
【问题描述】:
我关注 youtube 上的视频。当我尝试设置导航控制器项目时遇到了问题。
func setupNavigationBarItems() {
let twitterImage = UIImageView(image: UIImage(named: "twitter_icon"))
twitterImage.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
twitterImage.contentMode = .scaleAspectFit
navigationController?.navigationItem.titleView = twitterImage
let profileButton = UIButton(type: .system)
profileButton.setImage(UIImage(named: "profile_image"), for: .normal)
profileButton.frame = CGRect(x: 0, y: 0, width: 20, height: 20)
navigationController?.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: profileButton)
}
这就是结果。什么都没有显示
编辑—— 我做了同样的改变
navigationController?.navigationItem.leftBarButtonItem = UIBarButtonItem(customView: profileButton)
--
navigationItem.leftBarButtonItem = UIBarButtonItem(customView: profileButton)
它只显示 profileButton 和按钮延伸到边缘
【问题讨论】:
标签: ios swift uinavigationcontroller uikit uinavigationbar