Iphone 如何将图像动态排列成圆形
如何在圆形图像中动态排列图标(UIButtons,带有背景图像)。类似的东西应该像同心圆 我正在使用以下代码Iphone 如何将图像动态排列成圆形,iphone,ios,xcode,geometry,Iphone,Ios,Xcode,Geometry,如何在圆形图像中动态排列图标(UIButtons,带有背景图像)。类似的东西应该像同心圆 我正在使用以下代码 UIImageView *container = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0f, 299.0f, 298.0f)]; container.image = [UIImage imageNamed:@"AR_RF004_circle.png"]; container.center = CGPoi
UIImageView *container = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0f, 299.0f, 298.0f)];
container.image = [UIImage imageNamed:@"AR_RF004_circle.png"];
container.center = CGPointMake(self.view.bounds.size.width/2.0, self.view.bounds.size.height/2.0);
[self.view addSubview:container];
NSArray *imagesArray = [[NSArray alloc]initWithObjects:[UIImage imageNamed:@"AR1.png"],[UIImage imageNamed:@"AR2.png"],[UIImage imageNamed:@"AR3.png"],[UIImage imageNamed:@"AR4.png"],[UIImage imageNamed:@"AR5.png"], nil];
int numberOfSections = 5;
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, 128.0f)];
[sectionLabel setBackgroundImage:[imagesArray objectAtIndex:j] forState:UIControlStateNormal];
sectionLabel.layer.anchorPoint = CGPointMake(0.9f, 0.1f);
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];
NSLog(@"section label x and y is %f ,%f",sectionLabel.frame.origin.x,sectionLabel.frame.origin.y);
}
[container release];
UIImageView*container=[[UIImageView alloc]initWithFrame:CGRectMake(0.0,0.0f,299.0f,298.0f)];
container.image=[UIImage ImageName:@“AR_RF004_circle.png”];
container.center=CGPointMake(self.view.bounds.size.width/2.0,self.view.bounds.size.height/2.0);
[self.view addSubview:container];
NSArray*imagesArray=[[NSArray alloc]initWithObjects:[UIImage ImageName:@“AR1.png”]、[UIImage ImageName:@“AR2.png”]、[UIImage ImageName:@“AR3.png”]、[UIImage ImageName:@“AR4.png”]、[UIImage ImageName:@“AR5.png”]、nil];
int numberOfSections=5;
CGFloat angleSize=2*M_PI/截面数;
对于(int j=0;j
提前感谢您可以使用以下代码:
UIButton *currentButton;
int buttonCount = 20;
int radius = 200;
float angleBetweenButtons = (2 * M_PI) / buttonCount;
float x = 0;
float y = 0;
CGAffineTransform rotationTransform;
for (int i = 0; i < buttonCount; i++)
{
// get your button from array or something
currentButton = ...
...
x = radius + cosf(i * angleBetweenButtons) * radius;
y = radius + sinf(i * angleBetweenButtons) * radius;
rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, (i * angleBetweenButtons));
currentButton.center = CGPointMake(x, y);
currentButton.transform = rotationTransform;
}
ui按钮*currentButton;
int buttonCount=20;
int半径=200;
按钮之间的浮动角度=(2*M_PI)/按钮计数;
浮动x=0;
浮动y=0;
CGA仿射变换;旋转变换;
对于(int i=0;i
您可以使用以下代码:
UIButton *currentButton;
int buttonCount = 20;
int radius = 200;
float angleBetweenButtons = (2 * M_PI) / buttonCount;
float x = 0;
float y = 0;
CGAffineTransform rotationTransform;
for (int i = 0; i < buttonCount; i++)
{
// get your button from array or something
currentButton = ...
...
x = radius + cosf(i * angleBetweenButtons) * radius;
y = radius + sinf(i * angleBetweenButtons) * radius;
rotationTransform = CGAffineTransformIdentity;
rotationTransform = CGAffineTransformRotate(rotationTransform, (i * angleBetweenButtons));
currentButton.center = CGPointMake(x, y);
currentButton.transform = rotationTransform;
}
ui按钮*currentButton;
int buttonCount=20;
int半径=200;
按钮之间的浮动角度=(2*M_PI)/按钮计数;
浮动x=0;
浮动y=0;
CGA仿射变换;旋转变换;
对于(int i=0;i
我想你可以这样做
sectionLabel.center=container.center代码>
我没有检查其他代码。。最简单的方法我想你可以这样做
sectionLabel.center=container.center代码>
我没有检查其他代码。。最简单的方法是zakhej:我是否需要为开始按钮提供任何初始帧??您需要为按钮设置一个帧,使其具有大小。在设置中心之前执行此操作。这个代码基本上把按钮的中心点放在给定半径和角度等的圆的边缘上。zakhej:我是否需要为开始按钮提供任何初始帧??你需要为按钮设置一个帧,以便它有一个大小。在设置中心之前执行此操作。这个代码基本上把按钮中心点放在给定半径和角度的圆的边缘上。。。