【问题标题】:Xcode 6 Rounded Rect Button IssueXcode 6 圆角矩形按钮问题
【发布时间】:2014-12-25 03:56:48
【问题描述】:

在 Xcode 6 和 iOS 8.1 的 Objective-C 视图控制器中以编程方式创建圆角矩形按钮的尝试只会产生非圆角矩形按钮。正在使用 UIButton buttonWithType: 方法。

为什么?

//
//  ViewController.m
//

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)loadView // Called the first time the view property is accessed.
{
    CGRect viewRect = [[UIScreen mainScreen] bounds];
    UIView *view = [[UIView alloc] initWithFrame:viewRect];
    self.view = view;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Set the view's background color.
    self.view.backgroundColor = [UIColor colorWithRed:0.462 green:0.999 blue:0.999 alpha:1.0];

    // Create a button.
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    // Place and size the button on the screen.
    btn.frame = CGRectMake(100, 100, 90, 44);
    // Set the button's background color.
    btn.backgroundColor = [UIColor yellowColor];
    // Set the button's normal title.
    [btn setTitle:@"Test Button" forState:UIControlStateNormal];
    // Add the button as a subview.
    [self.view addSubview:btn];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

【问题讨论】:

  • 首先你应该在发布问题之前搜索SO,无论如何检查这个链接stackoverflow.com/a/19143035/2458651
  • Zaheer,您的评论和链接都没有帮助。在发布我的问题之前,我确实搜索过。谢谢你。
  • 亲爱的 Mario Abruzzi,答案的第一行是 buyButton.layer.cornerRadius = 2;

标签: objective-c xcode


【解决方案1】:

添加此行并尝试:

btn.layer.cornerRadius = 5;

【讨论】:

    猜你喜欢
    • 2015-11-12
    • 1970-01-01
    • 2013-09-28
    • 1970-01-01
    • 2013-08-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多