以编程方式在CircleImage上创建UIButtons

Sri*_*vas 5 iphone xcode geometry ios obshapedbutton

我需要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];
    }
Run Code Online (Sandbox Code Playgroud)

上面代码的图片

我试过这段代码,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];
}
Run Code Online (Sandbox Code Playgroud)

第二张图片

我需要输出如下图所示 第3张图片

我怎样才能实现这一目标

在我尝试了Sarah Zuo的代码之后的O/P.

 Sarah Zuo Code

相同的宽度和高度按钮 Sarah Zuo代码第二个答案
AnyKind of Help更受赞赏

Mau*_*lik 1

你可以用你的UIImageView代替。您可以赋予不同的tag图像视图并添加手势识别器。现在您可以获取触摸事件,例如图像视图上的按钮单击事件。