在iOS 6中为我的默认视图添加一个按钮

时间:2013-08-16 07:07:38

标签: ios ios6 uibutton

我有以下代码(刚开始学习ios):

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, 300, 600);
button.frame = frame;   

如何让它显示在我的视图上?并添加标题?

3 个答案:

答案 0 :(得分:2)

试试这个 在ViewDidLoad方法中编写此代码。

UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button setTitle:@"Show View" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
[self.view addSubview:button];

答案 1 :(得分:0)

使用addSubview添加以查看和使用属性title来设置标题

[button setTitle:@"Click me" forState:UIControlStateNormal];
[self.view addSubview:button];

答案 2 :(得分:0)

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, 300, 600);
button.frame = frame; 

此代码是正确的,只需在代码中使用addSubview

即可 像这样

[self.view addSubview:button];

并尝试使用此

[button setTitle:@"Btn" forState:UIControlStateNormal];