1.UIImageView圆角
- CALayer *l = [cell.imgAvatarImage layer];
- [l setMasksToBounds:YES];
- [l setCornerRadius:6.0];
2.UIImageView显示圆形
- UIImageView *imageView1 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"image.png"]];
- imageView1.frame = CGRectMake(60,100, 100, 100);
- imageView1.layer.masksToBounds =YES;
- imageView1.layer.cornerRadius =50;
- [self.view addSubview:imageView1];
3.UIImageView变灰效果
- + (UIImage*)getGrayImage:(UIImage*)sourceImage
- {
- int width = sourceImage.size.width;
- int height = sourceImage.size.height;
- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
- CGContextRef context = CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGImageAlphaNone);
- CGColorSpaceRelease(colorSpace);
- if (context == NULL) {
- return nil;
- }
- CGContextDrawImage(context,CGRectMake(0, 0, width, height), sourceImage.CGImage);
- CGImageRef grayImageRef = CGBitmapContextCreateImage(context);
- UIImage *grayImage = [UIImage imageWithCGImage:grayImageRef];
- CGContextRelease(context);
- CGImageRelease(grayImageRef);
- return grayImage;
- }
4 UIImage设置显示大小
- - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
- UIGraphicsBeginImageContext(size);
- [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
- UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
- // 使当前的context出堆栈
- UIGraphicsEndImageContext();
- // 返回新的改变大小后的图片
- return scaledImage;
- }