如何以编程方式创建基本的UIButton? [英] How do I create a basic UIButton programmatically?
本文介绍了如何以编程方式创建基本的UIButton?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何以编程方式创建基本的 UIButton
?例如在我的视图控制器中,当执行 viewDidLoad
方法时,将动态创建三个 UIButton
属性已设置。
How can I create a basic UIButton
programmatically? For example in my view controller, when executing the viewDidLoad
method, three UIButton
s will be created dynamically and its layout or properties are set.
推荐答案
以下是一个:
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];
这篇关于如何以编程方式创建基本的UIButton?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文