iOS 无法更改 UIButton 的框架

2023-07-07移动开发问题
1

本文介绍了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 的框架的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

硬件音量按钮更改应用程序音量
Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)...
2024-08-12 移动开发问题
10

恢复游戏 cocos2d
Resume game cocos2d(恢复游戏 cocos2d)...
2024-08-12 移动开发问题
6

Cocos2D + 仅禁用 Retina iPad 图形
Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)...
2024-08-12 移动开发问题
10

[ios.cocos2d+box2d]如何禁用自动旋转?
[ios.cocos2d+box2d]how to disable auto-rotation?([ios.cocos2d+box2d]如何禁用自动旋转?)...
2024-08-12 移动开发问题
7

从 Documents 目录存储和读取文件 iOS 5
Storing and reading files from Documents directory iOS 5(从 Documents 目录存储和读取文件 iOS 5)...
2024-08-12 移动开发问题
9

如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?
How can I implement a virtual joystick for a cocos2d game outside the cocos2d environment?(如何在 cocos2d 环境之外实现 cocos2d 游戏的虚拟摇杆?)...
2024-08-12 移动开发问题
13