0

尝试使用 uiimageviews 的 nsarray 创建一个 for 循环,但似乎无法让 cgrectmake 工作。

Location = CGRectMake(10, 10, 97, 110);
NSArray *cardImages = [[NSArray alloc]initWithObjects:car1,car2,card3,car4,car5,car6,car7,car8,car9,car10,car11, nil];
for (UIImageView *image in cardImages) {

    image.frame = Location;
    image.image = [UIImage imageNamed:@"ace.png"];
}
4

1 回答 1

0

In your current code you are setting the same frame to all UIImageView's. Try to change frame origin each iteration:

NSArray *cardImages = @[ card1, card2, card3, card4, card5, card6, card7, card8, card9, card10,card11 ];
for (int i = 0; i < [cardImages count]; i++) {
    UIImageView *image = cardImages[i];

    // Each iteration new frame will have bigger x position (0, 10, 20...)
    image.frame = CGRectMake(10 * i, 10, 97, 110);
    image.image = [UIImage imageNamed:@"ace.png"];
}
于 2013-09-09T03:26:54.747 回答