口袋优选

KBPushAlertView.m 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // KBPushAlertView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/10/12.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBPushAlertView.h"
  9. @implementation KBPushAlertView
  10. - (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self initSubViews:text];
  15. }
  16. return self;
  17. }
  18. - (void)initSubViews:(NSString *)text {
  19. UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.bounds];
  20. imgView.image = [UIImage imageNamed:@"pop_noti"];
  21. imgView.userInteractionEnabled = YES;
  22. [self addSubview:imgView];
  23. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(40), Fitsize(160), self.width-Fitsize(80), Fitsize(80))];
  24. label.textColor = [UIColor YHColorWithHex:0x444444];
  25. label.textAlignment = NSTextAlignmentCenter;
  26. label.font = [UIFont systemFontOfSize:Fitsize(17)];
  27. label.numberOfLines = 0;
  28. if ([text isKindOfClass:[NSNull class]]|| text==nil) {
  29. text = @"";
  30. }
  31. NSMutableAttributedString *att = [[NSMutableAttributedString alloc] initWithString:text];
  32. NSMutableParagraphStyle * paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  33. [paragraphStyle setLineSpacing:8];
  34. [att addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [att length])];
  35. label.attributedText = att;
  36. [imgView addSubview:label];
  37. UIButton *sure = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Fitsize(188), Fitsize(36))];
  38. [sure setTitle:@"开启通知" forState:UIControlStateNormal];
  39. sure.titleLabel.font = [UIFont systemFontOfSize:Fitsize(18)];
  40. [sure setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  41. [sure setBackgroundColor:[UIColor homeRedColor]];
  42. sure.layer.cornerRadius = Fitsize(5);
  43. [sure addTarget:self action:@selector(suerClick) forControlEvents:UIControlEventTouchUpInside];
  44. [imgView addSubview:sure];
  45. sure.centerX = self.width/2;
  46. UIButton *cancel = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, Fitsize(188), Fitsize(36))];
  47. [cancel setTitle:@"下次再说" forState:UIControlStateNormal];
  48. cancel.titleLabel.font = [UIFont systemFontOfSize:Fitsize(16)];
  49. cancel.titleLabel.textAlignment = NSTextAlignmentCenter;
  50. [cancel addTarget:self action:@selector(cancelClick) forControlEvents:UIControlEventTouchUpInside];
  51. [cancel setTitleColor:[UIColor YHColorWithHex:0x888888] forState:UIControlStateNormal];
  52. [imgView addSubview:cancel];
  53. cancel.centerX = self.width/2;
  54. sure.bottom = self.height-Fitsize(20);
  55. cancel.bottom = sure.top-5;
  56. }
  57. - (void)cancelClick {
  58. if (self.cancelBlock) {
  59. self.cancelBlock();
  60. }
  61. }
  62. - (void)suerClick {
  63. if (self.sureBlock) {
  64. self.sureBlock();
  65. }
  66. }
  67. @end