这是第一次与大家分享,如果不能帮到你请见谅。
btn的创建
btn的形状
UIButton *Btn = [UIButton buttonWithType:UIButtonTypeCustom];
这是btn的几个按钮类型
{
UIButtonTypeCustom = 0, // 没有按钮类型
UIButtonTypeSystem // 标准系统按钮
UIButtonTypeDetailDisclosure,
UIButtonTypeInfoLight,
UIButtonTypeInfoDark,
UIButtonTypeContactAdd,
UIButtonTypeSystem,
}
btn的位置
Btn.frame = CGRectMake(84, 176, 127, 46);
Btn.frame = CGRectMake(84, 176, 127, 46);
btn文字居中
Btn.titleLabel.textAlignment = NSTextAlignmentCenter;
这是字体靠左右和居中
{
NSTextAlignmentLeft
NSTextAlignmentCenter
NSTextAlignmentRight
}
Btn.titleLabel.textAlignment = NSTextAlignmentCenter;
这是字体靠左右和居中
{
NSTextAlignmentLeft
NSTextAlignmentCenter
NSTextAlignmentRight
}
btn上面添加文字
[Btn setTitle:@"创建btn" forState:UIControlStateNormal];
[Btn setTitle:@"创建btn" forState:UIControlStateNormal];
btn设置字体 这里我设置了字体和大小
Btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
Btn.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:18];
btn点击方法
[Btn addTarget:self action:@selector(点击方法) forControlEvents:UIControlEventTouchUpInside];
[Btn addTarget:self action:@selector(点击方法) forControlEvents:UIControlEventTouchUpInside];
btn字体的颜色
[Btn setTitleColor:[UIColor whiteColor] forState:UIControlStateReserved];
btn的圆角
Btn.layer.cornerRadius = 4.0;
Btn.layer.cornerRadius = 4.0;
btn的背景色
Btn.backgroundColor = [UIColor redColor];
Btn.backgroundColor = [UIColor redColor];
btn高亮显示
Btn.showsTouchWhenHighlighted = YES;
Btn.showsTouchWhenHighlighted = YES;
btn添加在view上面
[self.view addSubview :Btn];
[self.view addSubview :Btn];