我将一个UIButton
(带有背景图像)添加到导航栏并设置带有边框的圆角。我得到在角落一个奇怪的黑色轮廓:为什么在UIButton的圆角处出现粗糙的黑色边缘?
这里是我用来创建viewDidLoad
按钮的代码:
ProfileImageService *profileImageService = [ProfileImageService getService];
CGRect frame = CGRectMake(0, 0, 32, 32);
UIButton *button = [[UIButton alloc] initWithFrame:frame];
[button setBackgroundImage:profileImageService.profileImage forState:UIControlStateNormal];
[button addTarget:self action:@selector(showMenu) forControlEvents:UIControlEventTouchUpInside];
button.layer.cornerRadius = button.frame.size.height/2.0;
button.layer.masksToBounds = YES;
button.clipsToBounds = YES;
button.layer.borderWidth = 3;
button.layer.borderColor = [UIColor colorWithRed:0 green:0.67 blue:0.97 alpha:1].CGColor;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
我怎样才能使边界光滑,摆脱微妙的黑色轮廓?
化妆一个带有UIButtonTypeCustom的按钮(这样你将得到一个没有样式的按钮),然后设置它的框架。尝试一下。 – Pawan
@pawan我试着用'UIButton * button = [UIButton buttonWithType:UIButtonTypeCustom];'来创建按钮,然后设置框架,但我仍然有完全相同的问题。任何其他想法? – Martin