Programmatically create UIButtons on CircleImage

I need to create an Arch shape UIButtons, on the image of the circle (O / p need to look like Concentric Circles)

I am currently using 5 images, but in the future I can add multiple images. Dynamically I need to filter a circle image with added images.

I had a Piece of code sample, and O / P is the image below.

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];
    }

Image for Above Code

I tried this part of the code, and O / P is the image below.

 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];
}

2nd Image

I need my output as shown below. 3rd Image

How can i achieve this

O / P after I tried with the code of Sarah Zuo

Sarah zuo code

the same width and height Sarah Zuo code 2nd answer
buttons AnyKind of Help is more appreciated

+5
source share
4 answers

I can only answer the last part,

, . . , , .

+4
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];
}

.

+2

You can use instead UIImageView. You can display another tagimage and add a gesture recognizer . Now you can receive touch events, such as a button click event on images.

+1
source

If the image of all buttons looks like one (the same direction), the conversion value may work.

button.transform = CGAffineTransformMakeRotation(2*M_PI-angleSize*j);
button.center = CGPointMake(radius + radius * sin(angleSize * j) / 2, radius +  radius * cos(angleSize * j) / 2);

button slice

+1
source

All Articles