gpt4 book ai didi

ios - 圆形 UIButton

转载 作者:行者123 更新时间:2023-12-01 15:29:36 26 4
gpt4 key购买 nike

我想知道是否可以绘制圆形 UIButton(不是圆形矩形)。

当我在自定义类型的 UIButton 中添加圆形图像时,它看起来像一个圆形按钮。但是在按钮被点击的那一刻,按钮的边界变得可见,所以它看起来像一个方形按钮,然后当点击结束时它看起来像一个圆形按钮。
即使在点击发生的那一刻,我也希望按钮看起来像一个圆形按钮。这可能吗?

最佳答案

测试代码:

。H

    -(void)vijayWithApple; 

.m
   -(void)vijayWithApple{

NSLog(@"vijayWithApple Called");
}


UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];

[button setImage:[UIImage imageNamed:@"Micky.png"] forState:UIControlStateNormal];

[button addTarget:self action:@selector(vijayWithApple) forControlEvents:UIControlEventTouchUpInside];

[button setTitle:@"Show View" forState:UIControlStateNormal];

button.frame = CGRectMake(135.0, 180.0, 40.0, 40.0);//width and height should be same value

button.clipsToBounds = YES;

button.layer.cornerRadius = 20;//half of the width

button.layer.borderColor=[UIColor redColor].CGColor;

button.layer.borderWidth=2.0f;

[self.view addSubview:button];

结果

enter image description here

关于ios - 圆形 UIButton,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/666080/

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