ios - 导航栏后退按钮

标签 ios swift uinavigationcontroller

我有一个导航栏,我想使用此代码来更改文本,但不幸的是箭头也消失了。所以我添加了一个小于号,它起作用了,但它的大小不匹配。有办法解决这个问题吗?

这是我的代码

let backButton: UIBarButtonItem = UIBarButtonItem(title: " < Timeline", style: UIBarButtonItemStyle.Plain, target: self, action: nil)
navigationController?.navigationBar.topItem?.leftBarButtonItem = backButton

最佳答案

  1. 创建透明 View 。

  2. 为箭头图像添加固定大小的 ImageView ,或者您也可以使用 UILabel,因为它适合您的情况。

  3. 在 < 标签或 ImageView 旁边添加另一个 UILabel。您可以使用填充使其看起来均匀。

  4. 在透明 View 上添加标签或 ImageView 。

  5. 创建自定义 View 的 UIBarButtonItem,然后将其添加到导航栏。

关于ios - 导航栏后退按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34444194/

相关文章:

ios - 如何从 SwiftUI 调用 PHPhotoLibrary presentLimitedLibraryPicker?

swift - iOS 12 wkwebview 无法使用重定向?

ios - 为什么 self.navigationController PushViewController 不起作用?

ios - 如何在 objective-c 中返回对象的 UIColor?

ios - 无法在我的 iOS 应用程序中正确使用 github 库

ios - 具有 bool 属性的 CoreData 实体被保存为 NSNumber 对象

ios - 创建 CoreData 关系导致代码中出现 20 多个错误

ios - iOS 应用程序上的 HTML 输入文件,禁用 "take photo"选项

ios - 检查 CLPlacemark 的名称是否为街道地址

SWift 4 JSONDecoder 从 Alamofire 响应解码