KSCloudPremissionAlertView.m 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. //
  2. // KSCloudPremissionAlertView.m
  3. // KulexiuSchoolStudent
  4. //
  5. // Created by 王智 on 2024/7/23.
  6. //
  7. #import "KSCloudPremissionAlertView.h"
  8. #import <KSToolsLibrary/UIView+Animation.h>
  9. typedef NS_ENUM(NSInteger, PREMISSION_ACTION) {
  10. PREMISSION_ACTION_CANCLE = 1001,
  11. PREMISSION_ACTION_SURE = 1002,
  12. };
  13. @interface KSCloudPremissionAlertView ()
  14. @property (weak, nonatomic) IBOutlet UILabel *tipsMessage;
  15. @property (nonatomic, copy) CloudAlertButtonCallback cancel;
  16. @property (nonatomic, copy) CloudAlertButtonCallback confirm;
  17. @end
  18. @implementation KSCloudPremissionAlertView
  19. + (void)configDescMessage:(NSString *)descMsg cancel:(CloudAlertButtonCallback)cancel confirm:(CloudAlertButtonCallback)confirm {
  20. KSCloudPremissionAlertView *alertView = [[[NSBundle mainBundle] loadNibNamed:@"KSCloudPremissionAlertView" owner:self options:nil] firstObject];
  21. NSString *content = [NSString stringWithFormat:@"请%@访问权限", descMsg];
  22. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  23. [paragraphStyle setLineSpacing:4];//调整行间距
  24. paragraphStyle.lineBreakMode = NSLineBreakByTruncatingTail;
  25. NSMutableAttributedString *attrs = [[NSMutableAttributedString alloc] initWithString:content attributes:@{NSParagraphStyleAttributeName:paragraphStyle,NSFontAttributeName:[UIFont systemFontOfSize:14.0f weight:UIFontWeightSemibold],NSForegroundColorAttributeName:HexRGB(0x080808)}];
  26. [attrs addAttributes:@{NSForegroundColorAttributeName:HexRGB(0xFE445C)} range:[content rangeOfString:descMsg]];
  27. alertView.tipsMessage.attributedText = attrs;
  28. alertView.cancel = cancel;
  29. alertView.confirm = confirm;
  30. [alertView showAlert];
  31. }
  32. - (void)showAlert {
  33. _isShow = YES;
  34. UIView *displayView = [NSObject getKeyWindow];
  35. [displayView addSubview:self];
  36. [self mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.left.right.top.bottom.mas_equalTo(displayView);
  38. }];
  39. [displayView bringSubviewToFront:self];
  40. [self setPopAnimation];
  41. }
  42. - (void)dismissAlertView {
  43. _isShow = NO;
  44. [self removeFromSuperview];
  45. }
  46. - (IBAction)buttonAction:(UIButton *)sender {
  47. if (sender.tag == PREMISSION_ACTION_CANCLE) {
  48. self.cancel();
  49. }else {
  50. self.confirm();
  51. }
  52. [self dismissAlertView];
  53. }
  54. /*
  55. // Only override drawRect: if you perform custom drawing.
  56. // An empty implementation adversely affects performance during animation.
  57. - (void)drawRect:(CGRect)rect {
  58. // Drawing code
  59. }
  60. */
  61. @end