2012-03-29 186 views
7

Can任何人都可以告诉我如何使用界面构建器在iPhone中创建圆角按钮(圆形按钮)。在Iphone SDK中创建圆形按钮

感谢

+3

您可以创建一个用的CustomButton圆形图像为背景, 选择按钮类型CustomType – Bala 2012-03-29 07:53:15

+0

你可以找到属性检查器中的按钮类型属性 – Bala 2012-03-29 08:03:06

回答

2

如果你想比充满你要显示在圈内任何一个圆形创建图像的圆形按钮。确保你的图像有一个alpha通道,并删除你的圈子周围的所有区域,所以图像的背景是透明的(alpha = 0)。 (gimp是免费和易于使用的应用程序这样的图像)

在IB创建一个类型自定义按钮的圆形按钮。选择你的图像作为你的按钮的背景,你有它。

2

希望这将有助于

#import <QuartzCore/QuartzCore.h> 

CALayer * l = [control layer]; 
    [l setMasksToBounds:YES]; 
    [l setCornerRadius:5.0]; 
    [l setBorderWidth:2.0]; 

根据您的需要调整cornerRadius ..

+0

UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom]; [button setImage:[UIImage imageNamed:@“ABC.png”] forState:UIControlStateNormal]; [button addTarget:self action:@selector(btn_Click)orControlEvents:UIControlEventTouchUpInside]; button.frame = CGRectMake(135.0,180.0,40.0,40.0); button.clipsToBounds = YES; button.layer.cornerRadius = 20; //宽度的一半 button.layer.borderColor = [UIColor redColor] .CGColor; button.layer.borderWidth = 2.0f; [self.view addSubview:button]; 上面的代码工作正常,但没有在IB采取的按钮。 – 2012-03-30 09:50:04