我有以下代码(刚开始学习ios):
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
CGRect frame = CGRectMake(0.0, 0.0, 300, 600);
button.frame = frame;
如何让它显示在我的视图中?并添加标题?
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];
使用addSubview
添加到视图和使用属性title
设置标题
[button setTitle:@"Click me" forState:UIControlStateNormal];
[self.view addSubview:button];
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];