看一下下图:

正如您所看到的那样,边缘是尖锐的矩形,它们是从圆角按钮出来的.我怎么能不显示边缘而只显示圆形按钮?
更新(解决方案):
我使用以下代码来实现圆角:
UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:self.stopButton.bounds
byRoundingCorners:UIRectCornerAllCorners
cornerRadii:CGSizeMake(12.0, 12.0)];
// Create the shape layer and set its path
CAShapeLayer *maskLayer = [CAShapeLayer layer];
maskLayer.frame = self.stopButton.bounds;
maskLayer.path = maskPath.CGPath;
// Set the newly created shape layer as the mask for the image view's layer
self.stopButton.layer.mask = maskLayer;
Run Code Online (Sandbox Code Playgroud)
新问题:
这段代码给了我startButtonRound.layer.cornerRadius行的错误.
UIButton *roundStartButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
roundStartButton.frame = CGRectMake(10, 10, 100, 20);
[roundStartButton setBackgroundImage:[UIImage imageNamed:@"green_gradient.jpg"] forState:UIControlStateNormal];
roundStartButton.layer.cornerRadius = 12.0;
UIBarButtonItem *startButton = [[UIBarButtonItem alloc] initWithCustomView:roundStartButton];
Run Code Online (Sandbox Code Playgroud)
Tim*_*ies 17
你可以单独用CALayer做到这一点:
CALayer *myLayer = [CALayer layer];
[myLayer setMasksToBounds:YES];
[myLayer setCornerRadius:5.0f];
[myLayer setBorderWidth:1.0f];
[myLayer setBorderColor: [[UIColor blackColor] CGColor]];
[myLayer setBackgroundColor: [[UIColor whiteColor] CGColor]];
Run Code Online (Sandbox Code Playgroud)
您还需要包含QuartzCore框架并在您自己的框架中包含框架标头.
#include <QuartzCore/QuartzCore.h>
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助
蒂姆
我想所有这些都可以通过以下方式实现:
self.stopButton.layer.cornerRadius = 12.0;
Run Code Online (Sandbox Code Playgroud)
但你试过吗?
self.stopButton.opaque = NO;
self.stopButton.backgroundColor = [UIColor clearColor];
Run Code Online (Sandbox Code Playgroud)
?
| 归档时间: |
|
| 查看次数: |
7661 次 |
| 最近记录: |