我需要创建拱形UIButtons,在一个圆形的图像。( O/p需要看起来像同心圆),
目前我正在使用5个图像,但在未来我可能会添加更多的图像,动态我需要用添加的图像填充圆形图像。
我有一段示例代码,O/P如下图所示
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];
}

我已经尝试过这段代码,O/P如下图所示
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];
}

我需要我的输出如下图所示

我怎样才能做到这一点?
在我尝试使用Sarah Zuo的代码后的操作

相同宽度和高度的按钮

AnyKind of Help更受欢迎
发布于 2012-09-25 17:47:22
我只能回答后半部分,
如果你能够获得按钮的图片,那么你可以参考this tutorial。这可能会对你有帮助。如果你的图像具有透明的背景,你的图像就会形成。
发布于 2012-09-25 17:57:58
float radius = container.bounds.size.width / 2;
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(2*M_PI-angleSize*j);
button.center = CGPointMake(radius + radius * sin(angleSize * j) / 2, radius + radius * cos(angleSize * j) / 2);
[container addSubview:button];
}试试这段代码。
发布于 2012-09-25 17:18:30
您可以使用您的UIImageView。您可以为图片视图赋予不同的tag,并添加Gesture Recognizer。现在,您可以在图像视图上获得触摸事件,如按钮单击事件。
https://stackoverflow.com/questions/12579733
复制相似问题