通过设置按钮的contentEdgeInsets属性来调整按钮内容与按钮边框之间的距离。例如:
// 创建一个按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(50, 100, 100, 50);
[button setTitle:@"按钮" forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
button.backgroundColor = [UIColor blueColor];
// 设置按钮内容边距
button.contentEdgeInsets = UIEdgeInsetsMake(5, 10, 5, 10);
// 添加到视图中
[self.view addSubview:button];
上述代码中,通过设置button.contentEdgeInsets属性,将按钮的上、左、下、右边距分别设置为5、10、5、10,调整按钮内容与边框之间的距离。
上一篇:按钮内容不更新
下一篇:按钮内容在内部控件模板中不显示