gpt4 book ai didi

ios - 自定义多个标签或按钮

转载 作者:行者123 更新时间:2023-11-29 12:28:00 25 4
gpt4 key购买 nike

在我的 objective-c 代码中,我自定义了不同的标签和 UIButton,但我不知道如何将它们全部编辑在一起,例如:

[[CincKmButton layer] setCornerRadius:10];
[CincKmButton setClipsToBounds:YES];
[[CincKmButton layer] setBorderColor:
[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]];
[CincKmButton setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pickerBackground.jpg"]]];
[[CincKmButton layer] setBorderWidth:2.75];

[[DeuKmButton layer] setCornerRadius:10];
[DeuKmButton setClipsToBounds:YES];
[[DeuKmButton layer] setBorderColor:
[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]];
[DeuKmButton setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pickerBackground.jpg"]]];
[[DeuKmButton layer] setBorderWidth:2.75];

[[HalfButton layer] setCornerRadius:10];
[HalfButton setClipsToBounds:YES];
[[HalfButton layer] setBorderColor:
[[UIColor colorWithRed:0 green:0 blue:0 alpha:1] CGColor]];
[HalfButton setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pickerBackground.jpg"]]];
[[HalfButton layer] setBorderWidth:2.75];

不每次都重复怎么办?谢谢!

最佳答案

最简单的方法可能是创建按钮的 NSArray 和一个进行自定义的方法。它最终看起来像

...
for (UIButton *button in @[CincKmButton,DeuKmButton,HalfButton]) {
[self configureButton:button]
}
...

- (void) configureButton:(UIButton *)button {
[button setClipsToBounds:YES];
button.layer.cornerRadius = 10;
button.layer.borderColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:1].CGColor;
button.layer.borderWidth = 2.75;
[button setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pickerBackground.jpg"]]];
}

关于ios - 自定义多个标签或按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28501631/

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