gpt4 book ai didi

ios - 在iOS应用程序中的UIButtons上全局设置圆角

转载 作者:行者123 更新时间:2023-12-01 18:17:02 24 4
gpt4 key购买 nike

有没有一种方法可以像下面的颜色那样全局设置带有圆角的UIButton?

[[UIButton appearance] setBackgroundColor:[UIColor purpleColor]];

最佳答案

#import <QuartzCore/QuartzCore.h>

将此添加到您的头文件中。

然后在实施中
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(100, 100, 100,50);
[btn setTitle:@"Hello" forState:UIControlStateNormal];
[btn setBackgroundColor:[UIColor colorWithRed:128.0/255.0f green:0.0/255.0f blue:0.0/255.0f alpha:0.7]];
btn.frame = CGRectMake(100.0, 100.0, 120.0, 50.0);//width and height should be same value
btn.clipsToBounds = YES;

btn.layer.cornerRadius = 20;//half of the width
btn.layer.borderColor=[UIColor redColor].CGColor;
btn.layer.borderWidth=2.0f;

cornerRadius将为您解决问题。.如果需要更多信息,请让我知道.. :)

编辑

这不可能在全球范围内实现。使用 appearence时,使用 here is the list可以使用 UIAppearance进行自定义。您可以做的是可以创建UIButton的子类,然后在 setCornerRadius方法中编写 initWithCoder的实现。

关于ios - 在iOS应用程序中的UIButtons上全局设置圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20923790/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com