我一直在试图在iPhone上创建16x16图像的网格。麻烦与CGRectMake
- (void)viewDidLoad {
[super viewDidLoad];
int xLocation = 0;
for (int i=0; i <= 619; i++) {
if (((i % 30) == 0) && i != 0) { //if at end of column (30th row), moves x over 16 px to next column
xLocation += 16;
}
else {;}
CGRect imageRect = CGRectMake(xLocation, (16*i), 16, 16);
UIImageView *image = [[UIImageView alloc] initWithFrame:imageRect];
[image setImage:[UIImage imageNamed:@"Untitled-1.png"]];
[image setOpaque:YES];
NSLog(@"%d", xLocation);
[self.view addSubview:image];
[image release];
}
问题是int xLocation。出于某种原因,CGRectMake在x坐标槽中使用0而不是xLocation。我说“而不是”,因为下面的NSLog显示xLocation具有我想要的值,所以值的赋值工作正常。这里发生了什么?
非常感谢,我一直专注于xLocation,这实际上不是问题所在。 – Regan 2011-04-13 03:24:41