简体   繁体   English

导航栏标题视图重叠左栏按钮项

[英]Navigation Bar Title View Overlaps Left Bar Button Item

I have a custom left bar button item, a custom title view, and a custom right bar button item. 我有一个自定义左栏按钮项,自定义标题视图和自定义右栏按钮项。 They are all fixed space items, with the rightBarButton view being defined in the storyboard, and the left and title views defined in code. 它们都是固定的空间项,其中rightBarButton视图在故事板中定义,左视图和标题视图在代码中定义。 They are added to the navigation bar as follows: 它们将添加到导航栏,如下所示:

let leftButton = UIBarButtonItem()
leftButton.customView = myLeftBarView
navigationItem.leftBarButtonItem = leftButton

let rightButton = UIBarButtonItem()
rightButton.customView = myRightBarView
navigationItem.rightBarButtonItem = rightButton

navigationItem.titleView = myTitleView

This used to work fine when my rightBarButtonItem was small, however, now its around 80px wide and on smaller screen sizes (the iPhone 5 and 5s), the titleView is pushed over towards the left, and slightly overlaps my leftBarButtonItem . 当我的rightBarButtonItem很小时,这曾经工作得很好,但是,现在它的宽度大约为80px,屏幕尺寸较小(iPhone 5和5s), titleView被推向左边,并略微重叠我的leftBarButtonItem

How can I fix this? 我怎样才能解决这个问题?

I hope you have added left and right bar button items like this way. 我希望你这样添加左右栏按钮项。

let button: UIButton = UIButton (type: UIButtonType.Custom)
button.setImage(UIImage(named: "imageName"), forState: UIControlState.Normal)
button.addTarget(self, action: "backButtonPressed:", forControlEvents: UIControlEvents.TouchUpInside)
button.frame = CGRectMake(0, 0, 30, 30)
let barButton = UIBarButtonItem(customView: button)

self.navigationItem.leftBarButtonItem = barButton

Method to call. 打电话的方法。

func backButtonPressed(btn : UIButton) {

}

Hope this will help you. 希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM