我有以下代码(刚开始学习ios):
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, 300, 600);
button.frame = frame;
如何让它显示在我的视图上?并添加标题?
答案 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];