31.UIImageView

UIImageView等比例加载图片

self.imageView.contentMode  = UIViewContentModeScaleAspectFit;
self.imageView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

为UIImageView添加圆角

第一种方法:
UIGraphicsBeginImageContextWithOptions(self.imageView.frame.size, NO, 1.0);
[[UIBezierPath bezierPathWithRoundedRect:self.imageView.bounds cornerRadius:10]addClip];
[image drawInRect:self.imageView.bounds];
self.imageView.image    = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
第二种方法:

添加image的分类

- (UIImage *)circleImage
{
    UIGraphicsBeginImageContext(self.size);
    CGContextRef context    = UIGraphicsGetCurrentContext();
    CGRect rect = CGRectMake(0, 0, self.size.width, self.size.height);
    CGContextAddEllipseInRect(context, rect);
    CGContextClip(context);

    [self drawInRect:rect];
    
    UIImage *image  = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

+ (UIImage *)getCircleImage:(NSString *)image
{
    return [[self imageNamed:image] circleImage];
}

你可能感兴趣的:(31.UIImageView)