我一直在試圖在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