TUISecurityStrikeView.m 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. //
  2. // TUISecurityStrikeView.m
  3. // TIMCommon
  4. //
  5. // Created by wyl on 2023/10/11.
  6. // Copyright © 2023 Tencent. All rights reserved.
  7. #import "TUISecurityStrikeView.h"
  8. #import <TIMCommon/TIMDefine.h>
  9. @implementation TUISecurityStrikeView
  10. - (instancetype)initWithFrame:(CGRect)frame {
  11. self = [super initWithFrame:frame];
  12. if (self){
  13. [self setupView];
  14. }
  15. return self;
  16. }
  17. + (BOOL)requiresConstraintBasedLayout {
  18. return YES;
  19. }
  20. - (void)setupView {
  21. self.topLine = [[UIView alloc] initWithFrame:CGRectZero];
  22. self.topLine.backgroundColor = TUIDynamicColor(@"", TUIThemeModuleTIMCommon, @"#E5C7C7");
  23. [self addSubview:self.topLine];
  24. self.textLabel = [[UILabel alloc] initWithFrame:CGRectZero];
  25. [self addSubview:self.textLabel];
  26. self.textLabel.font = [UIFont systemFontOfSize:14];
  27. self.textLabel.text = TIMCommonLocalizableString(TUIKitMessageTypeSecurityStrike);
  28. self.textLabel.textColor = TUIDynamicColor(@"", TUIThemeModuleTIMCommon, @"#DA2222");
  29. self.textLabel.numberOfLines = 0;
  30. self.textLabel.textAlignment = isRTL()?NSTextAlignmentRight:NSTextAlignmentLeft;
  31. }
  32. // this is Apple's recommended place for adding/updating constraints
  33. - (void)updateConstraints {
  34. [super updateConstraints];
  35. [self.topLine mas_remakeConstraints:^(MASConstraintMaker *make) {
  36. make.top.mas_equalTo(kTUISecurityStrikeViewTopLineMargin);
  37. make.leading.mas_equalTo(10);
  38. make.trailing.mas_equalTo(-10);
  39. make.height.mas_equalTo(0.5);
  40. }];
  41. [self.textLabel sizeToFit];
  42. [self.textLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
  43. make.leading.mas_equalTo(10);
  44. make.bottom.mas_equalTo(-11);
  45. make.width.mas_equalTo(self);
  46. }];
  47. }
  48. + (UIImage *)changeImageColorWith:(UIColor *)color image:(UIImage *)image alpha:(CGFloat)alpha {
  49. UIGraphicsBeginImageContextWithOptions(image.size, NO, image.scale);
  50. CGContextRef context = UIGraphicsGetCurrentContext();
  51. CGContextTranslateCTM(context, 0, image.size.height);
  52. CGContextScaleCTM(context, 1.0, -1.0);
  53. CGContextSetAlpha(context, alpha);
  54. CGContextSetBlendMode(context, kCGBlendModeNormal);
  55. CGRect rect = CGRectMake(0, 0, image.size.width, image.size.height);
  56. CGContextClipToMask(context, rect, image.CGImage);
  57. [color setFill];
  58. CGContextFillRect(context, rect);
  59. UIImage*newImage = UIGraphicsGetImageFromCurrentImageContext();
  60. UIGraphicsEndImageContext();
  61. return newImage;
  62. }
  63. @end