您可以执行以下操作:
int nrmedals; //number of medals
CGPoint bottompos; //position of the lower left corner of the rectangle where you want to draw
float padding; //space between medals
float diameter; //diameter of the medals
if (nrmedals%2==0) { //even
for (int i=0; i<nrmedals; i+=2) {
draw medal one at position (bottompos.x,bottompos.y+ i/2 * (diameter + padding));
draw medal two at position (bottompos.x+diameter+padding ,bottompos.y + i/2 * (diameter + padding));
}
}else {//odd
for (int i=0; i<nrmedals-1; i+=2) {
draw medal one at position (bottompos.x,bottompos.y+ i/2 * (diameter + padding));
draw medal two at position (bottompos.x+diameter+padding ,bottompos.y + i/2 * (diameter + padding));
}
draw odd medal at position (bottompos.x +diameter/2+padding/2 ,bottompos.y+diameter * (nrmedals-1)/2 +padding);
}
这是基本思想(当然你可以用一个变量替换“2”,而不是每行 2 个奖牌,你有更多)
一些计算点的数学可能会关闭