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
287 views
in Technique[技术] by (71.8m points)

ios - Changing text in a UILabel is causing all my imageViews and buttons to go back to their original locations

Whenever I try and change a labels text with

_levelNumberLabel.text = [NSString stringWithFormat:@"%i", difficulty];

it keeps moving all my labels, images and buttons back to their original location. I have never had this problem before, and I know its this line of code because it doesnt happen when I delete it. Any ideas?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

The problem is that you're using auto layout and you've moved your interface around by setting the frame of your labels, images, and buttons. But frame and auto layout are opposites. Since you are using auto layout, you should have changed the constraints of your labels, images, and buttons.

So what's happening now is that you're setting the text of a label and this in turn is causing layout to happen. Layout, when auto layout is involved, means obeying the constraints. You didn't change the constraints, so, just as you say, this means that everything goes back to its original position - because that is what your constraints say to do.


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

...