我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
当前回答
你也可以使用界面构建器的用户定义运行时属性特性来设置关键路径层。拐角半径为一个值。确保你包含了QuartzCore库。
这个技巧也适用于设置图层。然而,borderWidth并不适用于图层。borderColor,因为它需要CGColor而不是UIColor。
您将无法在故事板中看到效果,因为这些参数是在运行时计算的。
其他回答
首先需要导入头文件<QuartzCore/QuartzCore.h>
#import QuartzCore/QuartzCore.h>
[yourView.layer setCornerRadius:8.0f];
yourView.layer.borderColor = [UIColor redColor].CGColor;
yourView.layer.borderWidth = 2.0f;
[yourView.layer setMasksToBounds:YES];
不要错过使用-setMasksToBounds,否则效果可能无法显示。
view.layer.cornerRadius = 25
view.layer.masksToBounds = true
你也可以使用界面构建器的用户定义运行时属性特性来设置关键路径层。拐角半径为一个值。确保你包含了QuartzCore库。
这个技巧也适用于设置图层。然而,borderWidth并不适用于图层。borderColor,因为它需要CGColor而不是UIColor。
您将无法在故事板中看到效果,因为这些参数是在运行时计算的。
设置圆形视图的转角属性
设置masksToBounds布尔值,图像将不会在角半径边界外绘制
view.layer.cornerRadius = 5;
view.layer.masksToBounds = YES;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(20, 50, 200, 200)];
view.layer.backgroundColor = [UIColor whiteColor].CGColor;
view.layer.cornerRadius = 20.0;
view.layer.frame = CGRectInset(v.layer.frame, 20, 20);
view.layer.shadowOffset = CGSizeMake(1, 0);
view.layer.shadowColor = [[UIColor blackColor] CGColor];
view.layer.shadowRadius = 5;
view.layer.shadowOpacity = .25;
[self.view addSubview:view];
[view release];