Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.2k views
in Technique[技术] by (71.8m points)

xcode - Adding constraints to a UIBarButtonItem

Xcode is not allowing me to put constraints on my BarButtonItem on a ViewController in the MainStoryBoard. It's appearing too far to the left where it's unreadable as shown in the image.

The image below shows where the BarButtonItem is. It's supposed to say "Item". I also looked on the preview split screen on Xcode and it looked fine for the iPhone6 but not for the iPhone 4 (it's half cut on the iPhone 4 but here its 3/4s cut). Here I'm running for the iPhone 6 and i get that.

How do I add constraints in Xcode or how do I add the constraints programmatically to this BarButtonItem?

enter image description here

Any help is much appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Drag and drop navigation bar in your xib / story board

enter image description here

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

Then add Bar Button Item to your navigation bar

enter image description here

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.

enter image description here

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.. :)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...