guardAlertView.m 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. //
  2. // guardAlertView.m
  3. // yunbaolive
  4. //
  5. // Created by Boom on 2018/11/12.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "guardAlertView.h"
  9. @implementation guardAlertView
  10. {
  11. UIView *alertView;
  12. }
  13. - (instancetype)initWithFrame:(CGRect)frame andType:(int)type andMsg:(NSString *)msg{
  14. self = [super initWithFrame:frame];
  15. if (self) {
  16. self.backgroundColor = RGB_COLOR(@"#000000", 0.1);
  17. [self creatUI:type and:msg];
  18. }
  19. return self;
  20. }
  21. - (void)creatUI:(int)type and:(NSString *)msg{
  22. alertView = [[UIView alloc]initWithFrame:CGRectMake(_window_width*0.15, _window_height/2-_window_width*0.2, _window_width*0.7, _window_width*0.4)];
  23. alertView.center = self.center;
  24. alertView.backgroundColor = [UIColor whiteColor];
  25. alertView.layer.cornerRadius = 5.0;
  26. alertView.layer.masksToBounds = YES;
  27. [self addSubview:alertView];
  28. UILabel *titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, alertView.height/8, alertView.width, alertView.height/32*3)];
  29. titleLabel.font = [UIFont systemFontOfSize:14];
  30. titleLabel.textColor = RGB_COLOR(@"#333333", 1);
  31. titleLabel.textAlignment = NSTextAlignmentCenter;
  32. titleLabel.text = YZMsg(@"提示");
  33. [alertView addSubview:titleLabel];
  34. UILabel *msgLabel = [[UILabel alloc]initWithFrame:CGRectMake(alertView.width/8, titleLabel.bottom, alertView.width*0.75, alertView.height/32*15)];
  35. msgLabel.font = [UIFont systemFontOfSize:12];
  36. msgLabel.textColor = RGB_COLOR(@"#636465", 1);
  37. msgLabel.numberOfLines = 0;
  38. msgLabel.text = msg;
  39. [alertView addSubview:msgLabel];
  40. [PublicObj lineViewWithFrame:CGRectMake(0, msgLabel.bottom, alertView.width, 1) andColor:RGB_COLOR(@"#e4e5e6", 1) andView:alertView];
  41. if (type == 1) {
  42. // msgLabel.text = YZMsg(@"您当前为主播的月守护,开通年守护将覆盖您的月守护剩余时长,是否开通?");
  43. NSArray *arr = @[YZMsg(@"取消"),YZMsg(@"确定")];
  44. for (int i = 0; i < arr.count; i++) {
  45. UIButton *button = [UIButton buttonWithType:0];
  46. button.frame = CGRectMake((alertView.width/2+0.5)*i, msgLabel.bottom+1, alertView.width/2-0.5, alertView.height*5/16-1);
  47. button.tag = 181112+i;
  48. [button setTitle:arr[i] forState:0];
  49. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  50. button.titleLabel.font = [UIFont systemFontOfSize:15];
  51. if (i == 0) {
  52. [button setTitleColor:RGB_COLOR(@"#636465", 1) forState:0];
  53. [PublicObj lineViewWithFrame:CGRectMake(button.right, button.top, 1, button.height) andColor:RGB_COLOR(@"#e4e5e6", 1) andView:alertView];
  54. }else{
  55. [button setTitleColor:Pink_Cor forState:0];
  56. }
  57. [alertView addSubview:button];
  58. }
  59. }else{
  60. // msgLabel.text = YZMsg(@"您当前为主播的年守护\n无法开通7天/月守护");
  61. msgLabel.textAlignment = NSTextAlignmentCenter;
  62. UIButton *button = [UIButton buttonWithType:0];
  63. button.frame = CGRectMake(0, msgLabel.bottom+1, alertView.width, alertView.height*5/16-1);
  64. button.tag = 181112;
  65. [button setTitle:YZMsg(@"确定") forState:0];
  66. [button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchUpInside];
  67. button.titleLabel.font = [UIFont systemFontOfSize:15];
  68. [button setTitleColor:Pink_Cor forState:0];
  69. [alertView addSubview:button];
  70. }
  71. }
  72. - (void)buttonClick:(UIButton *)sender{
  73. if (sender.tag == 181112) {
  74. self.block(NO);
  75. }else{
  76. self.block(YES);
  77. }
  78. }
  79. @end