iOS Clean corners for rounded profile image

前端 未结 3 607
野趣味
野趣味 2020-12-20 02:28

So I followed an AppCoda tutorial on rounding the corners of a profile image, and it worked fine, except for one thing. Wherever the image was rounded, there is a bit of bl

3条回答
  •  情歌与酒
    2020-12-20 03:15

    A simple solution is that you can enlarge layer's bounds a little bit to cover the edge of view's image:

    CGFloat offset = 1.f; // .5f is also good enough
    self.imageview.image = image;
    self.imageview.layer.cornerRadius = 10.0;
    self.imageview.layer.borderWidth = 3.0 + offset;
    self.imageview.layer.borderColor = UIColor.whiteColor().CGColor;
    self.imageview.layer.masksToBounds = YES;
    
    [self.imageview.layer setBounds:CGRectMake(-offset,
                                               -offset,
                                               CGRectGetWidth(self.imageview.frame)  + offset * 2.f,
                                               CGRectGetHeight(self.imageview.frame) + offset * 2.f)];
    

提交回复
热议问题