UIView+PublicInit.m 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // UIView+PublicInit.m
  3. // Asteria
  4. //
  5. // Created by iOS on 2023/4/24.
  6. //
  7. #import "UIView+PublicInit.h"
  8. @implementation UIView (PublicInit)
  9. // MARK: - base create
  10. + (UIView *)baseV {
  11. UIView *v = [[UIView alloc] init];
  12. v.backgroundColor = UIColor.whiteColor;
  13. return v;
  14. }
  15. + (UILabel *)baseLb {
  16. UILabel *lb = [[UILabel alloc] init];
  17. // lb.font = [UIFont fontWithName:Rob_Regular size:14];
  18. lb.textColor = [UIColor blackColor];
  19. lb.backgroundColor = [UIColor clearColor];
  20. return lb;
  21. }
  22. + (UIImageView *)baseImgV {
  23. UIImageView *imgV = [[UIImageView alloc] init];
  24. imgV.contentMode = UIViewContentModeScaleAspectFit;
  25. return imgV;
  26. }
  27. + (UIStackView *)baseStackV:(BOOL)isVertical {
  28. UIStackView *stackV = [[UIStackView alloc] init];
  29. stackV.axis = isVertical ? UILayoutConstraintAxisVertical : UILayoutConstraintAxisHorizontal;
  30. stackV.spacing = 8;
  31. stackV.alignment = UIStackViewAlignmentFill;
  32. stackV.distribution = UIStackViewDistributionFill;
  33. return stackV;
  34. }
  35. + (void)viewAddLineColorBg:(UIView *)bgV colorArr:(NSArray *)colors {
  36. CAGradientLayer *layer = [[CAGradientLayer alloc] init];
  37. layer.frame = bgV.bounds;
  38. layer.colors = colors;
  39. layer.startPoint = CGPointMake(0.22, 0.14);
  40. layer.endPoint = CGPointMake(0.8, 0.82);
  41. layer.locations = @[@0,@1.0f];
  42. layer.name = @"colorLayer";
  43. layer.cornerRadius = 4;
  44. [bgV.layer addSublayer:layer];
  45. }
  46. + (void)viewAddHorColorBg:(UIView *)bgV colorArr:(NSArray *)colors {
  47. CAGradientLayer *layer = [[CAGradientLayer alloc] init];
  48. layer.frame = bgV.bounds;
  49. layer.colors = colors;
  50. layer.startPoint = CGPointMake(0, 0.47);
  51. layer.endPoint = CGPointMake(1, 0.45);
  52. layer.locations = @[@0,@1.0f];
  53. layer.name = @"colorLayer";
  54. layer.cornerRadius = 4;
  55. [bgV.layer addSublayer:layer];
  56. }
  57. + (UIImage *)snapshotWithView:(UIView *)view {
  58. UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
  59. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  60. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  61. UIGraphicsEndImageContext();
  62. return image;
  63. }
  64. + (UIVisualEffectView *)getBlurV:(CGRect)frame {
  65. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  66. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  67. effectView.frame = frame;
  68. return effectView;
  69. }
  70. @end