如何以编程方式创建基本 UIButton
?例如在我的 View Controller 中,在执行 viewDidLoad
方法时,会动态创建三个 UIButton
并设置其布局或属性。
最佳答案
这是一个:
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button addTarget:self
action:@selector(aMethod:)
forControlEvents:UIControlEventTouchUpInside];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[view addSubview:button];
https://stackoverflow.com/questions/1378765/