我需要创建弧形的 UIButtons
,并放置在一个圆形图像上(输出结果需要呈现同心圆形)。
目前我正在使用 5 张图片,但将来可能会添加更多的图片,所以我需要动态地填充圆形图像。
我有一段示例代码,输出结果如下图所示:
int numberOfSections = 6;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int j = 0; j < numberOfSections; ++j) {
UIButton *sectionLabel = [[UIButton alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 150.0f, 2.0f)];
sectionLabel.backgroundColor = [UIColor redColor];
sectionLabel.layer.anchorPoint = CGPointMake(1.0f, 0.5f);
sectionLabel.layer.position = CGPointMake(container.bounds.size.width/2.0, container.bounds.size.height/2.0); // places anchorPoint of each label directly in the center of the circle.
sectionLabel.transform = CGAffineTransformMakeRotation(angleSize*j);
[container addSubview:sectionLabel];
}
我已经尝试使用这段代码,输出结果如下图所示:
int numberOfSections = 5;
CGFloat angleSize = 2*M_PI/numberOfSections;
for (int j = 0; j<numberOfSections; ++j) {
UIImage *imageframe = [imagesArray objectAtIndex:j];
OBShapedButton *button = [[OBShapedButton alloc] initWithFrame:CGRectMake(0.0f, 150.0f, 150.0f, 128.0f)];
button.transform = CGAffineTransformMakeRotation(angleSize*j);
[container addSubview:button];
}
我需要输出以下图片:
![第三张图片](https://istack.dev59.com/VTSZE.webp)
如何实现?
我试过了Sarah Zuo的代码,但输出不符合要求。
需要同样宽度和高度的按钮:
![Sarah Zuo 代码第二种答案](https://istack.dev59.com/3MeJ2.webp)
非常感谢您的帮助。