Adding constraints to a UIBarButtonItem

爷,独闯天下 提交于 2019-11-29 14:29:06

Drag and drop navigation bar in your xib / story board

U can add constraints to this navigation bar as per your requirement.

Then add Bar Button Item to your navigation bar

Bar Button Item takes it default position u cannot incorporate autolayout there.

Although if u want positions of Bar Button Item Fixed or Flexible u can make use of Fixed Space Bar Button Item or Flexible Space Bar Button Item.

If positions are fixed drag Fixed Space Bar Button between your two Bar Button Item's. And if positions is not fixed its flexible drag Flexible Space Bar Button Item between your two Bar Button Item's.

Happy Coding.. :)

Try this:

let rightConstraint = NSLayoutConstraint(item: your_item_here, attribute: .Right, relatedBy: .Equal, toItem: your_item_here, attribute: .Left, multiplier: 0, constant: 1)
your_item_here.addConstraint(rightConstraint)

P.S if you want to add constraint to your UIBarButtonItem, it will rise an error

Value of type 'UIBarButtonItem' has no member 'addConstraint'

P.S.S

Because of it is not a view class, you can't apply constraints to it.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!