问题描述
我目前遇到一个非常奇怪的问题.我正在使用 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 的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!