给ImageView添加约束后,在裁圆角作为头像,在ios9无效bug
通常方法在layoutSubviews,写这些,可以对付约束情况下的圆角,可是在ios9不起作用了,我用的是9.1测试版,解决办法是subclass,UIImageView,然后看后面代码
-(void)layoutSubviews
{
[super layoutSubviews];
[self layoutIfNeeded];
_imageViewIcon.layer.cornerRadius = _imageViewIcon.width/2;
_imageViewIcon.layer.masksToBounds = YES;
_imageViewIcon.clipsToBounds = YES;
// _imageViewIcon.layer.opaque = NO;
[_imageViewIcon setClipsToBounds:YES];
}
subclass:
-(instancetype)init
{
if (self = [super init]) {
}
return self;
}
-(void)layoutSubviews
{
[super layoutSubviews];
[self layoutIfNeeded];
self.layer.masksToBounds = YES;
self.layer.cornerRadius = self.width*0.5;
}