口袋优选

KBUpdateAlertView.m 2.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. //
  2. // KBUpdateAlertView.m
  3. // YouHuiProject
  4. //
  5. // Created by 小花 on 2018/10/15.
  6. // Copyright © 2018年 kuxuan. All rights reserved.
  7. //
  8. #import "KBUpdateAlertView.h"
  9. @implementation KBUpdateAlertView
  10. - (instancetype)initWithFrame:(CGRect)frame text:(NSString *)text isNeeded:(BOOL)isNeeded
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self initSubViews:text isNeeded:isNeeded];
  15. }
  16. return self;
  17. }
  18. - (void)initSubViews:(NSString *)text isNeeded:(BOOL)isNeeded{
  19. UIImageView *imgView = [[UIImageView alloc] initWithFrame:self.bounds];
  20. imgView.image = [UIImage imageNamed:@"pop_upda"];
  21. imgView.userInteractionEnabled = YES;
  22. [self addSubview:imgView];
  23. UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(Fitsize(20), Fitsize(190), self.width-Fitsize(40), Fitsize(120))];
  24. label.textColor = [UIColor YHColorWithHex:0x444444];
  25. label.textAlignment = NSTextAlignmentCenter;
  26. label.font = [UIFont systemFontOfSize:Fitsize(15)];
  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:4];
  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. cancel.hidden = isNeeded;
  55. sure.bottom = self.height-Fitsize(20);
  56. cancel.bottom = sure.top-5;
  57. }
  58. - (void)cancelClick {
  59. if (self.cancelBlock) {
  60. self.cancelBlock();
  61. }
  62. }
  63. - (void)suerClick {
  64. if (self.sureBlock) {
  65. self.sureBlock();
  66. }
  67. }
  68. @end