IOS: create a UIImage or UIImageView with rounded corners

后端 未结 12 767
执笔经年
执笔经年 2020-12-07 07:26

Is it possible create an UIImage or an UIImageView with rounded corners? Because I want take an UIImage and show it inside an UI

12条回答
  •  盖世英雄少女心
    2020-12-07 08:19

    Here how i set my rounded avatar at the center of it contain view:

    -(void)setRoundedAvatar:(UIImageView *)avatarView toDiameter:(float)newSize atView:(UIView *)containedView;
    {
        avatarView.layer.cornerRadius = newSize/2;
        avatarView.clipsToBounds = YES;
    
        avatarView.frame = CGRectMake(0, 0, newSize, newSize);
        CGPoint centerValue = CGPointMake(containView.frame.size.width/2, containedView.frame.size.height/2);
        avatarView.center = centerValue;
    }
    

提交回复
热议问题