iOS cannot change frame of UIButton(iOS 无法更改 UIButton 的框架)
问题描述
我目前遇到一个非常奇怪的问题.我正在使用 iOS 6 和 Xcode 4.5.我有一个带有 UIViewController 和 UIButton 的情节提要.我为我的 .h 文件制作了一个弱 UIButton 出口.
I am currently stuck with a very weird problem. I am using iOS 6 and Xcode 4.5. I have a storyboard with a UIViewController and a UIButton in it. I made a weak UIButton outlet to my .h file.
在 .m 文件中,我想更改按钮的框架,但没有任何反应.然而,我创建了一个 UIImageView,并以与 UIButton 相同的方式连接,但我可以毫无问题地更改 UIImageView 的框架.
In the .m file I want to change the frame of the button but nothing happens. Yet I have an UIImageView created and connected the same way as the UIButton but I can change the UIImageView's frame without any problems.
当我这样做时:
NSLog(@"%@", button)
我得到这个输出:
<UIButton: 0xa185a40; frame = (191 330; 73 44); opaque = NO; autoresize = TM+BM; layer = <CALayer: 0xa185640>>
这些是我的代码的相关部分:
And these are the relevant parts of my code:
-(void)viewDidLayoutSubviews{
[self addStampGrid];
}
-(void)addStampGrid {
// ...
[_button setFrame:CGRectMake(10,10,10,10)];
}
推荐答案
我在使用 XCode 4.5 和 iOS 6 作为部署目标时遇到了同样奇怪的问题.我没有使用故事板.我设法通过禁用界面生成器中的使用自动布局"选项来解决它.(在文件检查器->界面生成器文档中.
I had the same weird problem using XCode 4.5 and iOS 6 as deployment target. I am not using story board though. I managed to solve it by disabling the option "Use Autolayout" in the Interface Builder. (In the file inspector->Interface builder document.
希望对你有帮助
这篇关于iOS 无法更改 UIButton 的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iOS 无法更改 UIButton 的框架
基础教程推荐
- iOS - UINavigationController 添加多个正确的项目? 2022-01-01
- navigationItem.backBarButtonItem 不工作?为什么上一个菜单仍然显示为按钮? 2022-01-01
- UIImage 在开始时不适合 UIScrollView 2022-01-01
- 为什么姜饼模拟器方向卡在应用程序中? 2022-01-01
- Xcode UIView.init(frame:) 只能在主线程中使用 2022-01-01
- 如何将图像从一项活动发送到另一项活动? 2022-01-01
- 如何比较两个 NSDate:哪个是最近的? 2022-01-01
- Android Volley - 如何动画图像加载? 2022-01-01
- SwiftUI-ScrollViewReader的ScrollTo不滚动 2022-01-01
- Play 商店的设备兼容性问题 2022-01-01
