UIButton 修改 titlelabel 似乎改变了它的框架 [英] UIButton modifying titlelabel seems to change its frame

查看:21
本文介绍了UIButton 修改 titlelabel 似乎改变了它的框架的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

发生了一些奇怪的事情.基本上,我正在尝试重新创建消息传递应用程序.因此,当我尝试让发送"按钮在用户输入至少 1 个字符时从灰色变为蓝色时.

Something strange is happening. Basically, I am trying to recreate the messaging app. So when I am trying to get the Send button to change from Grey to blue when the user has typed in at least 1 character.

当我尝试更改 titleLabel 时出现问题,该按钮将消失.后来我发现它恢复到旧位置(当键盘没有显示时).

The problem comes when I am trying to change titleLabel, the button will disappear. Later I found out it reverts back to the old position (when the keyboard it not shown).

为什么要这样做?如果我不修改 titleLabel 一切正常.但是,如果我这样做,UIButton 将返回到原始位置.如果您需要任何示例代码,请告诉我,但我不知道该放什么,因为它只是 [self.button.titleLabel setTextColor: [UIColor blueColor];UITextViewdidChange 但它表现得很奇怪.

Why does it do this? If I do not modify the titleLabel everything works as usual. However, if I do, the UIButton goes back to the original location. If you need any sample code let me know, but I am not sure what to put on here as it's just [self.button.titleLabel setTextColor: [UIColor blueColor]; in the UITextViewdidChange but it's acting strange.

谢谢!艾伦

推荐答案

正如其他人在这里提到的,您可能正在与自动布局斗争".您不必放弃自动布局,您只需将 NSLayoutConstraint 绑定到 IBOutlet 属性,然后更新约束即可.如果您没有约束,则会自动为您创建一个约束 - 您应该手动创建一个并附加它.如果它是在代码中创建的,则通过代码找到它并保存对它的引用.

Well as mentioned here by others, you might be "fighting" with auto-layout. You do not have to ditch auto-layout, you could just bind the NSLayoutConstraint to an IBOutlet property, and update the constraint. If you do not have a constraint, then one is created automatically for you - you should create one manually and attach it. If it is created in code, the find it by code and save a reference to it.

您也可以回到更简单的 AutoResizing,它在自动布局之前就已经存在(并且还没有被弃用).

You could also go back to the simpler AutoResizing, which was there before auto-layout (and is not deprecated, yet).

这篇关于UIButton 修改 titlelabel 似乎改变了它的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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