【问题标题】:Create Circular Button in iPhone SDK [closed]在 iPhone SDK 中创建圆形按钮 [关闭]
【发布时间】:2012-04-12 20:23:32
【问题描述】:

谁能告诉我如何使用interface builder在iPhone中创建圆形按钮(Circular Button)?

【问题讨论】:

  • 您可以创建一个以圆形图像为背景的customButton,选择按钮类型为CustomType
  • 您可以在属性检查器中找到按钮类型属性

标签: iphone button


【解决方案1】:

希望这会有所帮助

#import <QuartzCore/QuartzCore.h> 

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

根据需要调整cornerRadius..

【讨论】:

  • UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [按钮 setImage:[UIImage imageNamed:@"ABC.png"] forState:UIControlStateNormal]; [按钮 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 中的按钮。
【解决方案2】:

如果你想要一个圆形按钮,而不是创建一个圆形的图像,填充你想要在圆形中显示的任何内容。确保您的图像具有 alpha 通道并删除圆圈周围的所有区域,以便图像的背景是透明的 (alpha =0)。 (gimp 是免费且易于使用的此类图像应用程序)

在 IB 中创建一个带有自定义按钮类型的圆形矩形按钮。选择您的图像作为按钮的背景,就可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-04-11
    • 2018-07-23
    相关资源
    最近更新 更多