ios - 如何以编程方式创建基本的 UIButton?

如何以编程方式创建基本 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/

相关文章:

ios - 设置 UITextField 的最大字符长度

objective-c - 在 Objective-C 中创建一个抽象类

objective-c - 如何将百分号添加到 NSString

ios - 在 ARC 下,IBOutlets 应该强还是弱?

objective-c - 如何检查 NSDictionary 或 NSMutableDiction

ios - 如何浏览文本字段(下一步/完成按钮)

ios - 如何将 UIButton 的标题设置为左对齐?

objective-c - 如何在 Xcode 4 中设置 NSZombieEnabled?

ios - 如何以编程方式在 iPhone 上发送短信?

ios - UITextField 文本更改事件