《省钱达人》与《猎豆优选》UI相同版。域名tbk

UIView+YHExtend.m 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // UIView+YHExtend.m
  3. // YouHuiProject
  4. //
  5. // Created by jcymac on 2018/5/19.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "UIView+YHExtend.h"
  9. @implementation UIView (YHExtend)
  10. -(UIImage *)changeToImage{
  11. // UIGraphicsBeginImageContextWithOptions(self.bounds.size, NO, 1.0); //NO,YES 控制是否透明
  12. //
  13. // [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  14. //
  15. // UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  16. //
  17. // CGRect myImageRect = self.bounds;
  18. //
  19. // CGImageRef imageRef = image.CGImage;
  20. //
  21. // CGImageRef subImageRef = CGImageCreateWithImageInRect(imageRef,myImageRect );
  22. //
  23. //
  24. //
  25. // CGContextRef context = UIGraphicsGetCurrentContext();
  26. //
  27. // CGContextDrawImage(context, myImageRect, subImageRef);
  28. //
  29. // UIImage* smallImage = [UIImage imageWithCGImage:subImageRef];
  30. //
  31. // CGImageRelease(subImageRef);
  32. //
  33. // UIGraphicsEndImageContext();
  34. // return smallImage;
  35. CGSize s = self.bounds.size;
  36. // 下面方法,第一个参数表示区域大小。第二个参数表示是否是非透明的。如果需要显示半透明效果,需要传NO,否则传YES。第三个参数就是屏幕密度了
  37. // UIGraphicsBeginImageContextWithOptions(s, NO, [UIScreen mainScreen].scale);
  38. UIGraphicsBeginImageContextWithOptions(s, NO, 0);
  39. [self.layer renderInContext:UIGraphicsGetCurrentContext()];
  40. UIImage*image = UIGraphicsGetImageFromCurrentImageContext();
  41. UIGraphicsEndImageContext();
  42. return image;
  43. }
  44. @end