我的登录视图有一个子视图,它有一个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,否则效果可能无法显示。
UIView* viewWithRoundedCornersSize(float cornerRadius,UIView * original)
{
// Create a white border with defined width
original.layer.borderColor = [UIColor yellowColor].CGColor;
original.layer.borderWidth = 1.5;
// Set image corner radius
original.layer.cornerRadius =cornerRadius;
// To enable corners to be "clipped"
[original setClipsToBounds:YES];
return original;
}
这是一种不同于Ed Marty的方法:
#import <QuartzCore/QuartzCore.h>
[v.layer setCornerRadius:25.0f];
[v.layer setMasksToBounds:YES];
你需要setMasksToBounds来从IB加载所有的对象…我有一个问题,我的视图得到了圆润,但没有IB的对象:/
这是固定的=D希望它有助于!
- 斯威夫特
在SwiftUI中,你可以直接在任何你想要的视图上使用拐角半径修饰器。 比如这个问题:
Text("Signing In…")
.padding(16)
.background(Color.red)
.cornerRadius(50)
注意,没有更多的菱形半径,所以即使你设置角半径超过高度的一半,它也会平滑圆润。
查看这个答案,了解如何在SwiftUI中圆角
你也可以使用界面构建器的用户定义运行时属性特性来设置关键路径层。拐角半径为一个值。确保你包含了QuartzCore库。
这个技巧也适用于设置图层。然而,borderWidth并不适用于图层。borderColor,因为它需要CGColor而不是UIColor。
您将无法在故事板中看到效果,因为这些参数是在运行时计算的。