我看着教程一步一步跟着写的,但是按钮就是不显示出来。
//
// ViewController.m
// UIButton
//
// Created by iMac on 1/6/20.
// Copyright © 2020 iMac. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
-(void) createUIRectButton
{
//创建一个Button对象,根据类型来创建Button
//圆角类btn:UIButtonTypeRoundedRect
//通过类方法来创建ButtonWithType:类名+方法名
UIButton* btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
//设置button按钮的位置
btn.frame = CGRectMake(100,100,100,40);
//设置按钮的文字内容
//@parameter
//P1:字符串类型,显示到按钮上的文字
//P2:设置文字显示的状态类型:UIControlStateNormal,正常状态
[btn setTitle:@"Nartai" forState:UIControlStateNormal];
//P1:显示的文字
//P2:显示文字的状态
[btn setTitle:@"Khurlee" forState:UIControlStateHighlighted];
//背景颜色
btn.backgroundColor = [UIColor blueColor];
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//添加到视图中并显示
[self.view addSubview:btn];
}
@end
https://blog.csdn.net/NiXingFuJiuHao/article/details/39967473
在viewDidLoad里面加上 [self createUIRectButton];