我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
当前回答
如果圆角在viewDidload()中不起作用,最好在viewDidLayoutSubview()中编写代码
-(void)viewDidLayoutSubviews
{
viewTextfield.layer.cornerRadius = 10.0 ;
viewTextfield.layer.borderWidth = 1.0f;
viewTextfield.layer.masksToBounds = YES;
viewTextfield.layer.shadowRadius = 5;
viewTextfield.layer.shadowOpacity = 0.3;
viewTextfield.clipsToBounds = NO;
viewTextfield.layer.shadowOffset = CGSizeMake(0.0f, 0.0f);
}
希望这能有所帮助!
其他回答
在Xcode 6上 你试一试
self.layer.layer.cornerRadius = 5.0f;
or
self.layer.layer.cornerRadius = 5.0f;
self.layer.clipsToBounds = YES;
试试这个
#import <QuartzCore/QuartzCore.h> // not necessary for 10 years now :)
...
view.layer.cornerRadius = 5;
view.layer.masksToBounds = true;
注意:如果你试图将圆角应用到UIViewController的视图,它不应该应用在视图控制器的构造函数中,而应该应用在-viewDidLoad中,在视图实际实例化之后。
设置圆形视图的转角属性
设置masksToBounds布尔值,图像将不会在角半径边界外绘制
view.layer.cornerRadius = 5;
view.layer.masksToBounds = YES;
使用UIView扩展:
extension UIView {
func addRoundedCornerToView(targetView : UIView?)
{
//UIView Corner Radius
targetView!.layer.cornerRadius = 5.0;
targetView!.layer.masksToBounds = true
//UIView Set up boarder
targetView!.layer.borderColor = UIColor.yellowColor().CGColor;
targetView!.layer.borderWidth = 3.0;
//UIView Drop shadow
targetView!.layer.shadowColor = UIColor.darkGrayColor().CGColor;
targetView!.layer.shadowOffset = CGSizeMake(2.0, 2.0)
targetView!.layer.shadowOpacity = 1.0
}
}
用法:
override func viewWillAppear(animated: Bool) {
sampleView.addRoundedCornerToView(statusBarView)
}
- 斯威夫特
在SwiftUI中,你可以直接在任何你想要的视图上使用拐角半径修饰器。 比如这个问题:
Text("Signing In…")
.padding(16)
.background(Color.red)
.cornerRadius(50)
注意,没有更多的菱形半径,所以即使你设置角半径超过高度的一半,它也会平滑圆润。
查看这个答案,了解如何在SwiftUI中圆角