MOTempTwoVC.m 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141
  1. //
  2. // MOTempTwoVC.m
  3. // MiMoLive
  4. //
  5. // Created by SuperC on 2025/3/31.
  6. //
  7. #import "MOTempTwoVC.h"
  8. #import "ArcButton.h"
  9. @interface MOTempTwoVC ()
  10. @property (nonatomic, strong) UIView *centerView;
  11. @property (nonatomic, strong) NSMutableArray<ArcButton *> *arcButtons;
  12. @end
  13. @implementation MOTempTwoVC
  14. - (void)viewDidLoad {
  15. [super viewDidLoad];
  16. // 设置视图背景色
  17. self.view.backgroundColor = [UIColor whiteColor];
  18. // 初始化按钮数组
  19. self.arcButtons = [NSMutableArray array];
  20. // 创建中心视图
  21. [self setupCenterView];
  22. // 创建环形按钮
  23. [self setupArcButtons];
  24. }
  25. #pragma mark - 初始化视图
  26. /**
  27. * 创建中心视图
  28. */
  29. - (void)setupCenterView {
  30. // 创建一个圆形视图作为中心
  31. CGRect centerFrame = CGRectMake(self.view.bounds.size.width/2 - 50,
  32. self.view.bounds.size.height/2 - 50,
  33. 100,
  34. 100);
  35. self.centerView = [[UIView alloc] initWithFrame:centerFrame];
  36. self.centerView.backgroundColor = [UIColor lightGrayColor];
  37. self.centerView.layer.cornerRadius = 50;
  38. [self.view addSubview:self.centerView];
  39. // 添加标签
  40. UILabel *label = [[UILabel alloc] initWithFrame:self.centerView.bounds];
  41. label.text = @"中心视图";
  42. label.textAlignment = NSTextAlignmentCenter;
  43. label.textColor = [UIColor darkGrayColor];
  44. [self.centerView addSubview:label];
  45. }
  46. /**
  47. * 创建环形按钮
  48. */
  49. - (void)setupArcButtons {
  50. // 中心点坐标
  51. CGPoint centerPoint = CGPointMake(self.view.bounds.size.width/2,
  52. self.view.bounds.size.height/2);
  53. // 内圆半径(中心视图半径 + 间距)
  54. CGFloat innerRadius = 50 + 5.0;
  55. // 环形按钮宽度
  56. CGFloat arcWidth = 30;
  57. // 按钮数量
  58. NSInteger buttonCount = 8;
  59. // 创建6个环形按钮,均匀分布在圆周上
  60. for (int i = 0; i < 6.0; i++) {
  61. // 计算每个按钮的起始角度和结束角度
  62. CGFloat sectorAngle = 2 * M_PI / 8.0; // 每个扇区的角度
  63. CGFloat startAngle = (6 - i) * sectorAngle;
  64. CGFloat endAngle = startAngle + sectorAngle * 0.95; // 留出一些间隔
  65. // 创建环形按钮
  66. ArcButton *arcButton = [[ArcButton alloc] initWithCenter:centerPoint
  67. radius:innerRadius
  68. arcWidth:arcWidth
  69. startAngle:startAngle
  70. endAngle:endAngle];
  71. // 设置按钮属性
  72. arcButton.tag = i + 1;
  73. arcButton.arcColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
  74. // arcButton.selectedArcColor = [self randomColor];
  75. arcButton.borderWidth = 1.0;
  76. arcButton.borderColor = [UIColor darkGrayColor];
  77. arcButton.touchAreaScale = 1.2; // 扩大点击区域
  78. arcButton.arcBackgroundImage = [UIImage imageNamed:@"icon_combo_btn_bg_normal"];
  79. arcButton.selectedArcBackgroundImage = [UIImage imageNamed:@"icon_combo_btn_bg_select"];
  80. // 设置按钮标题
  81. NSString *title = [NSString stringWithFormat:@"%d", i + 1];
  82. [arcButton setTitle:title forState:UIControlStateNormal];
  83. [arcButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
  84. [arcButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
  85. arcButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
  86. // 添加点击事件
  87. [arcButton addTarget:self action:@selector(arcButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
  88. // 添加到视图和数组
  89. [self.view addSubview:arcButton];
  90. [self.arcButtons addObject:arcButton];
  91. }
  92. }
  93. #pragma mark - 事件处理
  94. /**
  95. * 处理环形按钮点击事件
  96. */
  97. - (void)arcButtonTapped:(ArcButton *)sender {
  98. // 切换按钮选中状态
  99. sender.isArcSelect = !sender.isArcSelect;
  100. }
  101. #pragma mark - 辅助方法
  102. /**
  103. * 生成随机颜色
  104. */
  105. - (UIColor *)randomColor {
  106. CGFloat red = (CGFloat)arc4random() / UINT32_MAX;
  107. CGFloat green = (CGFloat)arc4random() / UINT32_MAX;
  108. CGFloat blue = (CGFloat)arc4random() / UINT32_MAX;
  109. return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
  110. }
  111. @end