尝试以编程方式在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
答案 0 :(得分:1)
添加此行并尝试:
btn.layer.cornerRadius = 5;