2010-02-04 53 views
0

我繼承一個UITableViewCell,並在初始化函數我做了以下內容:爲什麼UITableViewCell的backgroundView模糊的圖像

UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"packagelistcell_background.png"]]; 
[imageView setFrame:CGRectMake(0, 0, 300, 81)]; 
self.backgroundView = imageView; 
[imageView release]; 

時顯示在屏幕上,圖像會略顯模糊。爲了進行測試,我在桌面視圖上方放置了一個直立的UIImageView,圖像看起來很完美和清晰。表格視圖是分組表格視圖。你知道爲什麼它模糊了圖像嗎?

回答

1

我認爲單元格已被調整大小,backgroundView也是如此。

嘗試

imageView.autoresizingMask = UIViewAutoresizingNone; 
0

嘗試將imageView偏移0.5像素。

+0

那會怎麼辦? – rickharrison 2010-02-04 13:21:51

0

不幸的是@ freytag的解決方案並沒有爲我工作。

爲了解決這個問題,我給的UIImageView添加到一個UIView容器,並設置最後這個作爲我的自定義單元格的背景視圖,而不是直接設置的UIImageView的:

UIImageView *imgView = [[UIImageView alloc] initWithImage:@"cellBackground.png"]; 
UIView *backgrContainer = [[UIView alloc] initWithFrame:self.backgroundView.frame]; 
[backgrContainer addSubview:imgView]; 
[self setBackgroundView:backgrContainer];// instead of [self setBackgroundView:imgView]; 
[backgrContainer release]; 
[imgView release]; 

出於某種原因直接設置的UIImageView使它變得模糊(即使沒有調整大小)。設置autoresizingMask = None或contentMode <> UIImageView的ScaleToFill沒有解決我的問題。

也要小心UITableView風格,因爲使用分組樣式會導致單元格背景視圖的寬度變小,這也可能會調整圖像大小。

(Retina設備/模擬器似乎沒有關於單元格背景中模糊圖像的這個問題)