UIButtonTypeRoundedRect的框架

use*_*133 2 iphone

对于UIButton,我现在使用第一个UIButtonTypeCustom我想将其更改为RoundedRect但是当我将UIButtonTypeCustom更改为UIButtonTypeRoundedRect时,它显示白色的RoundedRect而不是为其指定的颜色,并且它还显示了圆形按钮后面的rect按钮框的边缘.所以我想知道如何解决这个问题.

UIButton *myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];

[myButton addTarget:self action:@selector(dismissView:) forControlEvents:UIControlEventTouchUpInside];

myButton.frame = CGRectMake(0, 0, 60, 30);

[myButton setTitle:@"Done" forState:UIControlStateNormal];

myButton.backgroundColor = [UIColor colorWithHue:1.0/12 saturation:2.0/3 brightness:4.0/10 alpha:1.0];

UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithCustomView:myButton];

[[self navigationItem] setLeftBarButtonItem:button animated:YES];
Run Code Online (Sandbox Code Playgroud)

感谢帮助.

Bep*_*ppe 9

嗯......我怕这是不可能改变你的backgroundColor UIButton如果是UIButtonTypeRoundedRect.

我的建议是创建一个UIButtonTypeCustom并更改其图层以模仿a UIButtonTypeRoundedRect.

试试这段代码:

#import <QuartzCore/QuartzCore.h>

[myButton.layer setMasksToBounds:YES];
[myButton.layer setCornerRadius:10.0f];
[myButton.layer setBackgroundColor:[UIColor whiteColor].CGColor;
Run Code Online (Sandbox Code Playgroud)