gpt4 book ai didi

iphone - 使用方形 setBackgroundImage 的圆角 UIButton

转载 作者:可可西里 更新时间:2023-11-01 04:08:59 25 4
gpt4 key购买 nike

所以我创建了一个按钮。我希望它有圆角而不制作圆形的 .png 文件我可以设置背景图片。我可以绕过角落。但是,当我设置背景图像时,圆角消失了。

很久以前我做过一次,但似乎无法让它再次工作。如何做到这一点?

UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
[button1 addTarget:self action:@selector(goSpecials)
forControlEvents:UIControlEventTouchUpInside];
[button1 setTitle:@"Specials" forState:UIControlStateNormal];
button1.titleLabel.font = [UIFont fontWithName:@"Arial-BoldMT" size:(15.0)];
[button1 setTitleColor:[self colorWithHexString:buttonColor] forState:UIControlStateNormal];
button1.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed: @"button.png"]];
//[button1 setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
button1.frame = CGRectMake(20.0, 232.0, 135.0, 32.0);
button1.layer.borderColor = [UIColor blackColor].CGColor;
button1.layer.borderWidth = 0.5f;
button1.layer.cornerRadius = 8.0f;
[self.view addSubview:button1];

按钮.png: enter image description here

最佳答案

将 maskToBounds 属性添加到您的按钮。

button1.layer.masksToBounds = YES;

关于iphone - 使用方形 setBackgroundImage 的圆角 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10554667/

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