UIImageView变灰

1.UIImageView圆角

  1. CALayer *l = [cell.imgAvatarImage layer];
  2. [l setMasksToBounds:YES];
  3. [l setCornerRadius:6.0];

2.UIImageView显示圆形

  1. UIImageView *imageView1 = [[UIImageViewalloc] initWithImage:[UIImageimageNamed:@"image.png"]];
  2. imageView1.frame = CGRectMake(60,100, 100, 100);
  3. imageView1.layer.masksToBounds =YES;
  4. imageView1.layer.cornerRadius =50;
  5. [self.view addSubview:imageView1];

3.UIImageView变灰效果

  1. + (UIImage*)getGrayImage:(UIImage*)sourceImage
  2. {
  3. int width = sourceImage.size.width;
  4. int height = sourceImage.size.height;
  5. CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceGray();
  6. CGContextRef context = CGBitmapContextCreate (nil,width,height,8,0,colorSpace,kCGImageAlphaNone);
  7. CGColorSpaceRelease(colorSpace);
  8. if (context == NULL) {
  9. return nil;
  10. }
  11. CGContextDrawImage(context,CGRectMake(0, 0, width, height), sourceImage.CGImage);
  12. CGImageRef grayImageRef = CGBitmapContextCreateImage(context);
  13. UIImage *grayImage = [UIImage imageWithCGImage:grayImageRef];
  14. CGContextRelease(context);
  15. CGImageRelease(grayImageRef);
  16. return grayImage;
  17. }

4 UIImage设置显示大小

    1. - (UIImage *)scaleToSize:(UIImage *)img size:(CGSize)size{
    2. UIGraphicsBeginImageContext(size);
    3. [img drawInRect:CGRectMake(0, 0, size.width, size.height)];
    4. UIImage* scaledImage = UIGraphicsGetImageFromCurrentImageContext();
    5. // 使当前的context出堆栈
    6. UIGraphicsEndImageContext();
    7. // 返回新的改变大小后的图片
    8. return scaledImage;
    9. }
上一篇:探索 vuex 2.0 以及使用 vuejs 2.0 + vuex 2.0 构建记事本应用23


下一篇:SQl中drop与truncate的区别