YBAlertActionSheet.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. //
  2. // YBAlertActionSheet.m
  3. // yunbaolive
  4. //
  5. // Created by ybRRR on 2020/5/29.
  6. // Copyright © 2020 cat. All rights reserved.
  7. //
  8. #import "YBAlertActionSheet.h"
  9. @implementation YBAlertActionSheet
  10. -(instancetype)initWithFrame:(CGRect)frame cancelTitle:(NSString *)cancelText cancelColor:(UIColor *)cancelcolors andRowHeight:(int)rowH andOtherTitle:(NSArray *)otherArr
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. self.backgroundColor =RGBA(10, 10, 10, 0.4);
  15. cancelBtn = [UIButton buttonWithType:0];
  16. cancelBtn.frame = CGRectMake(10, _window_height-rowH-15, _window_width-20, rowH);
  17. [cancelBtn setTitle:cancelText forState:(UIControlState)0];
  18. [cancelBtn setTitleColor:cancelcolors forState:0];
  19. cancelBtn.titleLabel.font = [UIFont systemFontOfSize:15];
  20. cancelBtn.layer.cornerRadius = 10;
  21. cancelBtn.layer.masksToBounds = YES;
  22. [cancelBtn setBackgroundColor:[UIColor whiteColor]];
  23. [cancelBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  24. [self addSubview:cancelBtn];
  25. titleBack = [[UIView alloc]initWithFrame:CGRectMake(10, _window_height-rowH-25-rowH*otherArr.count, _window_width-20, rowH*otherArr.count)];
  26. titleBack.layer.cornerRadius = 10;
  27. titleBack.layer.masksToBounds = YES;
  28. titleBack.backgroundColor = [UIColor whiteColor];
  29. [self addSubview:titleBack];
  30. for (int i = 0; i < otherArr.count ; i ++) {
  31. UIButton *btn = [UIButton buttonWithType:0];
  32. btn.frame = CGRectMake(0, i * rowH, titleBack.width, rowH);
  33. [btn setTitle:otherArr[i] forState:0];
  34. [btn setTitleColor:[UIColor blackColor] forState:0];
  35. btn.titleLabel.font = [UIFont systemFontOfSize:15];
  36. [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  37. [titleBack addSubview:btn];
  38. if (i != 0) {
  39. UILabel *lineLb = [[UILabel alloc]initWithFrame:CGRectMake(0, i * rowH, titleBack.width, 1)];
  40. lineLb.backgroundColor = RGB(240, 240, 240);
  41. [titleBack addSubview:lineLb];
  42. }
  43. }
  44. }
  45. return self;
  46. }
  47. -(void)btnClick:(UIButton *)sender{
  48. if (self.btnEvent) {
  49. self.btnEvent(sender.titleLabel.text);
  50. }
  51. }
  52. @end