【发布时间】:2021-03-03 05:24:54
【问题描述】:
我有一个navigationBar,我想在左边有一个button,一个activityIndicator 作为title,在右边有一个doneButton。这是我尝试过的:
let activityIndicator = UIActivityIndicatorView(frame: CGRect(x: 0, y: 0, width: 25, height: 25))
let googleImage = UIImage(named: "google")!
let googleButton = UIBarButtonItem(image: googleImage, style: .plain, target: self, action: #selector(googleButtonTapped))
googleButton.image = UIImage(named: "google")?.withRenderingMode(UIImage.RenderingMode.alwaysOriginal)
navigationController?.navigationBar.barTintColor = UIColor.blueCustom
navigationController?.navigationBar.tintColor = UIColor.white
activityIndicator.hidesWhenStopped = true
activityIndicator.color = .white
self.navigationItem.titleView = self.activityIndicator
self.navigationItem.leftBarButtonItem = googleButton
self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Fertig", style: .done, target: self, action: #selector(doneTapped))
问题是googleButton和activityIndicator不在左边/中间:
我在这里错过了什么?
更新:
我尝试使用title 将leftBarButtonItem 设置为一个简单的项目,它可以作为expexted..为什么它不能与图像一起使用?
【问题讨论】:
-
你用图片初始化了googleButton bar item,为什么你稍后重新分配
googleButton.image呢?尝试使用Debug View Hierarchy -
我解决了这个问题,但这并没有导致问题。它打破了导航栏的几个约束,但我不知道为什么
-
可以分享图片链接下载吗?
标签: ios swift uiview uinavigationbar