[英]How can we round the UIImageView using autolayouts
在我的项目中,在我的 tableview 单元格上添加了图像,为此我尝试了一些代码,但没有用,我在这里做错了什么?
在这里,我的主要要求是我想将该图像四舍五入(如圆形格式)。
我的代码:
Personimage = [[UIImageView alloc]init];
Personimage.image = [UIImage imageNamed:@"ram.jpeg"];
Personimage.translatesAutoresizingMaskIntoConstraints = NO;
[Cell.contentView addSubview:Personimage];
//Applying autolayouts
NSDictionary * viewsDic = NSDictionaryOfVariableBindings(Personimage)
[Cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-10-[Personimage(80)]"
options:0
metrics:nil
views:viewsDic]];
[Cell.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-10-[Personimage(80)]"
options:0
metrics:nil
views:viewsDic]];
}
-(Void)ViewDidAppear
{
Personimage.layer.cornerRadius = Personimage.frame.size.width / 2;
Personimage.layer.borderWidth = 3.0f;
Personimage.layer.borderColor = [UIColor whiteColor].CGColor;
Personimage.clipsToBounds = YES;
}
应用自动布局后,我在 viewDidAppear 方法中保留了图像“圆形”属性,但仍然无法正常工作,我在这里做错了什么? 请帮我一个人
您可以使用此代码来舍入UIImageView
imgView.layer.cornerRadius = imgView.frame.size.width / 2;
imgView.clipsToBounds = YES;
属性 clipsToBounds 是一个Bool
值,将其值从 YES 更改为 true 将起作用。
与斯威夫特一起玩得开心!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.