| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- //
- // MOTempTwoVC.m
- // MiMoLive
- //
- // Created by SuperC on 2025/3/31.
- //
- #import "MOTempTwoVC.h"
- #import "ArcButton.h"
- @interface MOTempTwoVC ()
- @property (nonatomic, strong) UIView *centerView;
- @property (nonatomic, strong) NSMutableArray<ArcButton *> *arcButtons;
- @end
- @implementation MOTempTwoVC
- - (void)viewDidLoad {
- [super viewDidLoad];
-
- // 设置视图背景色
- self.view.backgroundColor = [UIColor whiteColor];
-
- // 初始化按钮数组
- self.arcButtons = [NSMutableArray array];
-
- // 创建中心视图
- [self setupCenterView];
-
- // 创建环形按钮
- [self setupArcButtons];
- }
- #pragma mark - 初始化视图
- /**
- * 创建中心视图
- */
- - (void)setupCenterView {
- // 创建一个圆形视图作为中心
- CGRect centerFrame = CGRectMake(self.view.bounds.size.width/2 - 50,
- self.view.bounds.size.height/2 - 50,
- 100,
- 100);
- self.centerView = [[UIView alloc] initWithFrame:centerFrame];
- self.centerView.backgroundColor = [UIColor lightGrayColor];
- self.centerView.layer.cornerRadius = 50;
- [self.view addSubview:self.centerView];
-
- // 添加标签
- UILabel *label = [[UILabel alloc] initWithFrame:self.centerView.bounds];
- label.text = @"中心视图";
- label.textAlignment = NSTextAlignmentCenter;
- label.textColor = [UIColor darkGrayColor];
- [self.centerView addSubview:label];
- }
- /**
- * 创建环形按钮
- */
- - (void)setupArcButtons {
- // 中心点坐标
- CGPoint centerPoint = CGPointMake(self.view.bounds.size.width/2,
- self.view.bounds.size.height/2);
-
- // 内圆半径(中心视图半径 + 间距)
- CGFloat innerRadius = 50 + 5.0;
-
- // 环形按钮宽度
- CGFloat arcWidth = 30;
-
- // 按钮数量
- NSInteger buttonCount = 8;
-
- // 创建6个环形按钮,均匀分布在圆周上
- for (int i = 0; i < 6.0; i++) {
- // 计算每个按钮的起始角度和结束角度
- CGFloat sectorAngle = 2 * M_PI / 8.0; // 每个扇区的角度
- CGFloat startAngle = (6 - i) * sectorAngle;
- CGFloat endAngle = startAngle + sectorAngle * 0.95; // 留出一些间隔
-
- // 创建环形按钮
- ArcButton *arcButton = [[ArcButton alloc] initWithCenter:centerPoint
- radius:innerRadius
- arcWidth:arcWidth
- startAngle:startAngle
- endAngle:endAngle];
-
- // 设置按钮属性
- arcButton.tag = i + 1;
- arcButton.arcColor = [UIColor colorWithRed:0.8 green:0.8 blue:0.8 alpha:1.0];
- // arcButton.selectedArcColor = [self randomColor];
- arcButton.borderWidth = 1.0;
- arcButton.borderColor = [UIColor darkGrayColor];
- arcButton.touchAreaScale = 1.2; // 扩大点击区域
- arcButton.arcBackgroundImage = [UIImage imageNamed:@"icon_combo_btn_bg_normal"];
- arcButton.selectedArcBackgroundImage = [UIImage imageNamed:@"icon_combo_btn_bg_select"];
-
- // 设置按钮标题
- NSString *title = [NSString stringWithFormat:@"%d", i + 1];
- [arcButton setTitle:title forState:UIControlStateNormal];
- [arcButton setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
- [arcButton setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
- arcButton.titleLabel.font = [UIFont boldSystemFontOfSize:14];
-
- // 添加点击事件
- [arcButton addTarget:self action:@selector(arcButtonTapped:) forControlEvents:UIControlEventTouchUpInside];
-
- // 添加到视图和数组
- [self.view addSubview:arcButton];
- [self.arcButtons addObject:arcButton];
- }
- }
- #pragma mark - 事件处理
- /**
- * 处理环形按钮点击事件
- */
- - (void)arcButtonTapped:(ArcButton *)sender {
- // 切换按钮选中状态
- sender.isArcSelect = !sender.isArcSelect;
- }
- #pragma mark - 辅助方法
- /**
- * 生成随机颜色
- */
- - (UIColor *)randomColor {
- CGFloat red = (CGFloat)arc4random() / UINT32_MAX;
- CGFloat green = (CGFloat)arc4random() / UINT32_MAX;
- CGFloat blue = (CGFloat)arc4random() / UINT32_MAX;
- return [UIColor colorWithRed:red green:green blue:blue alpha:1.0];
- }
- @end
|