【发布时间】:2012-09-25 09:12:19
【问题描述】:
我需要在圆形图像上创建拱形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 的代码后的 O/P
相同的宽度和高度按钮
AnyKind 的帮助更受赞赏
【问题讨论】:
-
新图像是否会被添加到同一个圆圈中,从而减少现有图像视图的当前弧度??
-
@AppleDelegate :是的,我们将计算图像数量以便进行划分
标签: iphone ios xcode geometry obshapedbutton