Sam*_*mBo 11 xcode objective-c uibutton ios
我见过一些解决方案,其中没有一个能解决我的问题.
我UIButton
只需拖放到UIViewController
Storyboard编辑器中即可创建.
在UIButton
具有连接到.h文件的一个出口UIViewController
相关联的那个视图.它也是.m
文件中的Synthesized .
@property (strong, nonatomic) IBOutlet UIButton *answerButton;
Run Code Online (Sandbox Code Playgroud)
我想在运行时更改按钮的位置,就像这样;
CGRect btFrame = answerButton.frame;
btFrame.origin.x = xOne;
btFrame.origin.y = yOne;
answerButton.frame = btFrame;
Run Code Online (Sandbox Code Playgroud)
但是每当我尝试这个时,按钮就会拒绝移动.
所有其他编辑功能(如setTitle
等)都是可用的,但由于某种原因,框架不会按我想要的方式移动.
小智 7
.h文件
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController{
IBOutlet UIButton *theButton;
}
@property(nonatomic, strong) IBOutlet UIButton *theButton;
-(IBAction)moveTheButton:(id)sender;
@end
Run Code Online (Sandbox Code Playgroud)
.m文件
-(IBAction)moveTheButton:(id)sender{
CGRect btFrame = theButton.frame;
btFrame.origin.x = 90;
btFrame.origin.y = 150;
theButton.frame = btFrame;
Run Code Online (Sandbox Code Playgroud)
}
此代码将按钮从一个点移动到另一个点.
归档时间: |
|
查看次数: |
22792 次 |
最近记录: |