iOS 无法更改 UIButton 的框架 [英] iOS cannot change frame of UIButton

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

问题描述

我目前遇到一个非常奇怪的问题.我正在使用 iOS 6 和 Xcode 4.5.我有一个带有 UIViewControllerUIButton 的情节提要.我为我的 .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 的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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