我在 viewDidLoad() 方法中创建了一个自定义按钮并设置了 Autoresizingmask。它运作良好。但是当我将相同的代码放在按钮单击事件中时,它不会自动调整大小。有没有其他方法可以访问AutoresizingMask
内部点击事件?提前致谢。
在此处输入代码
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.backgroundColor=[UIColor redColor];
button.frame=CGRectMake(20, 373, 73, 43);
button.autoresizingMask=(UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth);
[self.view addSubview:button];
}
-(IBAction)btn_clicked
{
UIButton *btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[btn setTitle:@"Dynamic Btn" forState:UIControlStateNormal];
enter code here
btn.backgroundColor=[UIColor yellowColor];
btn.frame=CGRectMake(20, 150, 73, 43);
btn.autoresizingMask=UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
[self.view addSubview:btn];
}