我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
我的登录视图有一个子视图,它有一个UIActivityView和一个UILabel,上面写着“Signing In…”这个子视图有不圆角的角。我怎样才能把它们变圆呢?
有什么办法在我的xib里面做吗?
当前回答
Swift 4 -使用IBDesignable
@IBDesignable
class DesignableView: UIView {
}
extension UIView
{
@IBInspectable
var cornerRadius: CGFloat {
get {
return layer.cornerRadius
}
set {
layer.cornerRadius = newValue
}
}
}
其他回答
这是一种不同于Ed Marty的方法:
#import <QuartzCore/QuartzCore.h>
[v.layer setCornerRadius:25.0f];
[v.layer setMasksToBounds:YES];
你需要setMasksToBounds来从IB加载所有的对象…我有一个问题,我的视图得到了圆润,但没有IB的对象:/
这是固定的=D希望它有助于!
试试这个
#import <QuartzCore/QuartzCore.h> // not necessary for 10 years now :)
...
view.layer.cornerRadius = 5;
view.layer.masksToBounds = true;
注意:如果你试图将圆角应用到UIViewController的视图,它不应该应用在视图控制器的构造函数中,而应该应用在-viewDidLoad中,在视图实际实例化之后。
在obj c中通过编程实现吗
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;][1]
[self.view addSubview:view];
我们也可以从stoaryboard做这个。
layer.cornerRadius Number 5
设置圆形视图的转角属性
设置masksToBounds布尔值,图像将不会在角半径边界外绘制
view.layer.cornerRadius = 5;
view.layer.masksToBounds = YES;
如果圆角在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);
}
希望这能有所帮助!