UIView+PublicInit.m 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. + (void)viewAddHorColorBg:(UIView *)bgV colorArr:(NSArray *)colors startP:(CGPoint)start endP:(CGPoint)end {
  58. CAGradientLayer *layer = [[CAGradientLayer alloc] init];
  59. layer.frame = bgV.bounds;
  60. layer.colors = colors;
  61. layer.startPoint = start;
  62. layer.endPoint = end;
  63. layer.locations = @[@0,@1.0f];
  64. layer.name = @"colorLayer";
  65. // layer.cornerRadius = 4;
  66. [bgV.layer addSublayer:layer];
  67. }
  68. + (UIImage *)snapshotWithView:(UIView *)view {
  69. UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
  70. [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  71. UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
  72. UIGraphicsEndImageContext();
  73. return image;
  74. }
  75. + (UIVisualEffectView *)getBlurV:(CGRect)frame {
  76. UIBlurEffect *effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
  77. UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:effect];
  78. effectView.frame = frame;
  79. return effectView;
  80. }
  81. - (void)setLayerShadow:(UIColor*)color offset:(CGSize)offset radius:(CGFloat)radius {
  82. self.layer.shadowColor = color.CGColor;
  83. self.layer.shadowOffset = offset;
  84. self.layer.shadowRadius = radius;
  85. self.layer.shadowOpacity = 1;
  86. self.layer.shouldRasterize = YES;
  87. self.layer.rasterizationScale = [UIScreen mainScreen].scale;
  88. }
  89. @end