2016-05-23 30 views
0

我試着將它設置爲背景的UICell之前設置的圖像色調的顏色,但它只是根據我的UIColor返回純色setTint上UICell返回純色

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"]; 
    if (cell == nil) { 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"]; 
    } 
    UIImage *testImage = [UIImage imageNamed:@"ImageName.png"]; 
    testImage = [testImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
    UIImageView *testView = [[UIImageView alloc] initWithImage:testImage]; 

    [testView setTintColor:[UIColor greenColor]]; 
    cell.backgroundView = testView; 

} 

回答

0

如果細胞顯示爲純色,這意味着圖像本身是不透明的。 UIImageRenderingModeAlwaysTemplate基於該像素的圖像中存在的alpha通道上的每個像素的顏色(即,如果沒有透明度,則會得到純色)。你可以閱讀更多關於in the documentation here

+0

我明白了。我不明白的是,我所看到的關於此事的所有資料都表明,要改變圖像的色調,上面的代碼就足夠了。那麼我怎麼去着色一個圖像呢? – justMike

+0

根據這篇文章應該是可行的? http://stackoverflow.com/questions/1223340/iphone-how-do-you-color-an-image/4630136#4630136 – justMike

+0

我實現了這個類別,我用同一個純色http:// stackoverflow.com/questions/1223340/iphone-how-do-you-color-an-image/27356928#27356928 – justMike