【发布时间】:2017-05-25 20:51:42
【问题描述】:
我用代码在集合视图控制器中添加左导航返回按钮。
//Add Navigation Bar
navbar.autoresizingMask = [.flexibleWidth, .flexibleBottomMargin, .flexibleRightMargin]
navbar.delegate = self
UINavigationBar.appearance().barTintColor = UIColor(red: 0.0/255.0, green:49.0/255.0, blue:79.0/255.0, alpha:0.1)
UINavigationBar.appearance().tintColor = UIColor.white
UINavigationBar.appearance().isTranslucent = true
UINavigationBar.appearance().titleTextAttributes = [NSForegroundColorAttributeName : UIColor.white]
navItem.title = prefs.value(forKey: "PROVIDER_NAME") as! String?
let image = UIImage(named: "back_image")
navItem.leftBarButtonItem = UIBarButtonItem(image: image, style: .plain, target: self, action: #selector(addTapped))
navItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 0, 0, 0)
返回按钮离左边很近。我想从左边添加大约 10px 的填充。
所以,我把代码改成了
navItem.leftBarButtonItem?.imageInsets = UIEdgeInsetsMake(0, 15, 0, 0)
但它不起作用,并且图像后退按钮看起来更小。如何在“返回”按钮的左侧添加空间?
【问题讨论】:
-
你把这个视图控制器嵌入到
UINavigationController吗? -
@ArtemStepanenko,我没有嵌入 UINavigationController 兄弟
-
首先你需要用 navigationController 嵌入你的 viewController 并查看这个帖子 stackoverflow.com/questions/43546132/… 和 stackoverflow.com/questions/40504860/…
标签: swift3 uicollectionview uinavigationbar uinavigationitem