Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 以编程方式在CircleImage上创建UI按钮_Iphone_Ios_Xcode_Geometry_Obshapedbutton - Fatal编程技术网

Iphone 以编程方式在CircleImage上创建UI按钮

Iphone 以编程方式在CircleImage上创建UI按钮,iphone,ios,xcode,geometry,obshapedbutton,Iphone,Ios,Xcode,Geometry,Obshapedbutton,我需要在圆形图像上创建拱形按钮(O/p需要看起来像同心圆) 目前我使用5个图像,但在未来我可能会添加一些更多的图像,动态我需要fil的圆圈图像与添加的图像 我有一段代码示例,O/p如下图所示 int numberOfSections = 6; CGFloat angleSize = 2*M_PI/numberOfSections; for (int j = 0; j < numberOfSections; ++j) { UIButton *sectionLabel

我需要在圆形图像上创建拱形按钮(O/p需要看起来像同心圆)

目前我使用5个图像,但在未来我可能会添加一些更多的图像,动态我需要fil的圆圈图像与添加的图像

我有一段代码示例,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];
    }
 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];
}
int numberOfSections=6;
CGFloat angleSize=2*M_PI/截面数;
对于(int j=0;j

我试过使用这段代码,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];
    }
 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];
}
int numberOfSections=5;
CGFloat angleSize=2*M_PI/截面数;

对于(int j=0;j您可以使用您的
UIImageView
来代替。您可以为图像视图提供不同的
标记并添加。现在您可以在图像视图上获得触摸事件,如按钮单击事件。

我只能回答最后一部分

如果您能够获取按钮的图像,则可以参考。这可能会对您有所帮助。前提是,您形成的图像具有透明背景。

float radius=container.bounds.size.width/2;
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];
}
int numberOfSections=5; CGFloat angleSize=2*M_PI/截面数;
对于(int j=0;j如果所有按钮的图像看起来像一个(同一方向),则变换值可能是功

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

新图像是否会添加到同一个圆圈中,从而减少现有图像视图的当前弧???@AppleDelegate:是的,我们将给出图像计数,以便进行分割圆图像是一个UIImageView,现在当我尝试使用代码时,我得到了内部部分作为五边形当我尝试使用这段代码时,我得到了我更新了我的答案,你能检查一下问题的最后一张截图吗?我似乎对button.center和button.transform使用了错误的值。我修正了中心值,但按钮的各个部分都混淆了。是的,我希望你能检查一下,如果可能的话,我正在尝试使用不同的值,我没有得到正确的输出,你能检查一下吗that@CrazyCreator:我只是将图像放置在按钮背景中,但如何才能获得圆形按钮。你永远无法创建圆形按钮,这是你需要的技巧。保持其他部分透明,你的按钮将看起来像圆形。尽管他按钮有相同的宽度dn高度我得到相同的类型,我要我添加该图像也,请检查图像最后添加在2mins@Srinivas有什么好的吗?