2012-07-30 129 views
0

讓我開始與我的代碼:縮放圖像以適合平鋪

UIImage *tempImage = [UIImage imageNamed:@"TileMap.gif"]; 
[tempImage drawInRect:CGRectMake(0, 0, tileSize, tileSize)]; 


mapLabels[w][h] = [[UILabel alloc] initWithFrame:CGRectMake(cursor.x, cursor.y, tileSize, tileSize)]; 
mapLabels[w][h].text = [NSString stringWithFormat:@"%d", map[w][h]]; 
mapLabels[w][h].backgroundColor = [UIColor colorWithPatternImage: tempImage]; 
mapLabels[w][h].textAlignment = UITextAlignmentCenter; 


[self.view addSubview:mapLabels[w][h]]; 

我做了一個地圖瓦片出UILabels。我想在標籤上放一個Image,所以我用colorWithPatternImage。它的作品,但我的瓷磚圖片是非常高的分辨率和我的UILabel瓷磚可以是任何尺寸,所以我需要的圖像是相同的大小。我目前試圖用drawInRect進行縮放的方法不起作用,有什麼提示?

回答

0

UIImages有一個比例屬性。你可以嘗試這樣的:

tempImage.scale = mapLabels[w][h].tileSize.x/tempImage.tileSize.x