[英]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.