我在viewDidLoad()方法中創建了一個自定義按鈕,並設置了Autoresizingmask。它運作良好。但是當我把相同的代碼放在Button Click事件中時,它不會自動調整。有沒有其他方法可以在點擊事件中訪問AutoresizingMask
?提前致謝。AutoresizingMask無法在Click事件中工作
在這裏輸入代碼
- (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];
}
「AutoresizingMask Not Working」的含義是什麼?你期望按鈕點擊什麼? –
它是AutoresizingMask不工作還是添加子視圖? –