- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//创建UIButton
UIButton *button1 = [UIButton buttonWithType:UIButtonTypeRoundedRect];
button1.frame = CGRectMake(10, 30, 300, 30);
[button1 setTitle:@"圆角按钮" forState:UIControlStateNormal];
// 这句无效
// button1.titleLabel.textAlignment = NSTextAlignmentLeft;
button1.titleLabel.backgroundColor = [UIColor grayColor];
button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
button1.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[button1.layer setBorderColor:[UIColor grayColor].CGColor];
[button1.layer setBorderWidth:1];
[button1.layer setCornerRadius:5.0f];
[button1.layer setMasksToBounds:YES];
[self.view addSubview:button1];
}
本文将指导您如何在iOS应用中创建一个自定义的圆角按钮,包括按钮的样式设置、文字对齐方式、背景颜色调整、边框宽度、内边距、圆角效果以及如何确保按钮边界缩放。
790

被折叠的 条评论
为什么被折叠?



