iOS UIImageView如何为圆形ImageView添加填充

问题描述 投票:0回答:2

我有一个RoundImageView扩展UIImageView与以下功能,使其成为圆形:

-(void) makeImageViewRounded {
    //set the look of the image
    self.layer.backgroundColor=[[UIColor blackColor] CGColor];
    //self.layer.cornerRadius= self.frame.size.height /2;
    self.clipsToBounds = YES;
    self.layer.masksToBounds = YES;
    self.layer.borderWidth=1.0;
    self.layer.borderColor=[[UIColor grayColor] CGColor];
}

如何在边框和实际图像(填充)之间创建边距?我想暴露在self.layer.backgroundColor=[[UIColor blackColor] CGColor];中设置的颜色

ios uiimageview uiimage
2个回答
0
投票

yourImageView为100 * 100,填充= 10.然后将图像调整为80 * 80并设置此图像。

并将UIImageViewcontentMode财产设为AspectFit


-2
投票

创建一个比你的UIImageView更大的UIView并拥有Border。然后将ImageView放在其中心。

© www.soinside.com 2019 - 2024. All rights reserved.