我想知道是否可以绘制圆形UIButton(不是圆角矩形).
当我在自定义类型的UIButton中添加圆形图像时,它看起来像一个圆形按钮.但是在点击按钮的那一刻,按钮的边界变得可见,因此它看起来像一个方形按钮,然后当点击结束时它再次看起来像一个圆形按钮.
即使在点击发生的那一刻,我希望按钮看起来像一个圆形按钮.这可能吗?
经测试的代码:
.H
-(void)vijayWithApple;
Run Code Online (Sandbox Code Playgroud)
.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];
Run Code Online (Sandbox Code Playgroud)
结果
