问题描述
|
我已经看过很多关于这个问题的问答,但是这些都不是我想要做的。我在视图内部有一个视图,它的框架是CGRectangle。我想说矩形具有圆角的边缘,看起来像一个圆角的矩形按钮。如果我能提供一些有关如何实现的代码示例,那就太好了。先感谢您。
解决方法
您首先需要将QuartzCore框架导入到您的项目中。希望您知道该怎么做。比您可以使用以下代码:
CALayer *l = [yourView layer];
[l setMasksToBounds:YES];
[l setCornerRadius:10.0];
// You can even add a border
[l setBorderWidth:1.0];
[l setBorderColor:[[UIColor blackColor] CGColor]];
希望能帮助到你! ;)
, 您需要确保导入<QuartzCore/QuartzCore.h>
并将QuartzCore
添加到现有框架中才能访问cornerRadius:
方法。
然后设置拐角半径,您将根据视图的实现使用如下所示的内容
UIView *theView = [[UIView alloc] initWithFrame:CGRectMake(10,10,100,200)];
CALayer *theViewLayer = [theView layer];
[theViewLayer setCorderRadius:5.0];
//Other Methods you can use
[theViewLayer setBorderColor:[[UIColor colorWithWhite:1.0 alpha:0.3] CGColor]];
[theViewLayer setBorderWidth:2.0];
[theViewLayer setBackgroundColor:[[UIColor blackColor] CGColor]];