2011-03-25 143 views
0

我想給我分組的UITableView中的單元格半透明圖像作爲背景。我嘗試了很多不同的方式,但似乎無法讓它工作。這是我到目前爲止:分組的UITableViewCell透明背景圖像

-(void) viewWillAppear:(BOOL) animated{ 
[super viewWillAppear:animated]; 
self.table.backgroundColor = [UIColor clearColor];} 

-(UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 


UIImage *cellBackground; 
NSInteger sectionRows = [tableView numberOfRowsInSection:[indexPath section]]; 
NSInteger row = [indexPath row]; 


if (row == 0) 
{ 
    cellBackground = [UIImage imageNamed:@"tCT.png"]; 
} 

else if (row == sectionRows -1) 
{ 
    cellBackground = [UIImage imageNamed:@"tableCellBottom.png"]; 
} 

else 
{ 
    cellBackground = [UIImage imageNamed:@"tableCellMiddle.png"]; 
} 

cell.backgroundColor = [UIColor clearColor]; 
UIView *cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 
cellBackView.backgroundColor = [UIColor colorWithPatternImage: cellBackground]; 
cell.backgroundView = cellBackView; 

所以目前圖像顯示出來,但它的透明度並不明顯。背景是堅實的灰色(而不是半透明的灰色)。圓角組桌角上還有黑角。

任何想法,我要去哪裏錯了?

+0

您的圖像是否已經透明?因爲如果沒有,你必須設置imageView alpha。 – 2011-03-25 11:03:27

+0

圖像絕對透明。我在Photoshop中創建它,導出爲Web和設備並勾選'透明度'。 Finder的QuickLook中透明度顯示正常。 – Luke 2011-03-25 11:42:59

回答

0

將您的手機的contentViewbackgroundColor設置爲clearColor以刪除黑色邊框。

self.contentView.backgroundColor = [UIColor clearColor]; 
+0

我將它設置爲cell.contentView.backgroundColor = [UIColor clearColor];但仍然沒有運氣。 – Luke 2011-03-25 11:43:40

+0

我認爲黑色邊框可能是這個位: UIView * cellBackView = [[[UIView alloc] initWithFrame:CGRectZero] autorelease]; 我不熟悉以編程方式創建視圖,但我假設此代碼正在創建一個矩形視圖,即沒有圓角的視圖? – Luke 2011-03-25 17:15:19