我想知道画一个圆形的UIButton(不是四舍五入的矩形)是否可能。
当我在自定义类型的UIButton中添加一个圆形图像时,它看起来就像一个圆形按钮。但是在按钮被点击的时刻,按钮的边界变得可见,因此它看起来像一个方形按钮,然后当点击结束时,它看起来像一个圆形按钮。
我希望按钮看起来像一个圆形按钮,即使在点击发生的那一刻。这个是可能的吗?
发布于 2009-03-20 13:51:01
你可能不得不为此创建一个自定义控件,但是你真的需要一个圆形按钮吗?
每个平台都有自己的UI约定,iPhone也不例外。用户希望按钮是圆角矩形。
回应评论的更新:
如果我没弄错的话,你要找的不是一个圆形按钮,而是一个可点击(可触摸)的图像。
您可以使用UIImageView及其touchesBegan方法。
更新2:
等一下。我们说的是哪种单选按钮?不知怎么的,我还以为你在模仿真正的无线电呢。如果您正在讨论radio button组,请使用UISegmentedControl或UIPicker。
发布于 2011-08-05 17:18:58
测试代码:
.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];结果

发布于 2009-03-20 22:09:07
只需创建两个圆形按钮图像,一个用于按下状态,另一个用于未按下状态。
在IB中,创建一个自定义类型的UIButton。转到设置背景图像的部分,并将带有"All“的下拉列表设置为normal -现在将图像设置为您未按下的图像。
然后将下拉菜单更改为"Selected",并放入您按下的图像。
现在将填充类型更改为aspect fit,并使按钮成为正方形。用作普通的UIButton anywhere。当然,您也可以使用类似的步骤(为UIControlStateNormal和UIControlStateSelected设置图像)轻松地编程完成所有这些操作。
https://stackoverflow.com/questions/666080
复制相似问题