更改UILabel中的文本会导致我的所有imageView和按钮返回其原始位置 [英] Changing text in a UILabel is causing all my imageViews and buttons to go back to their original locations

查看:55
本文介绍了更改UILabel中的文本会导致我的所有imageView和按钮返回其原始位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每当我尝试使用

_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?

推荐答案

问题是你正在使用自动布局,你已经通过设置 frame 您的标签,图片和按钮。但 frame 和自动布局是对立的。由于您使用的是自动布局,因此您应该更改标签,图像和按钮的约束

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.

这篇关于更改UILabel中的文本会导致我的所有imageView和按钮返回其原始位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆