我想給我分組的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;
所以目前圖像顯示出來,但它的透明度並不明顯。背景是堅實的灰色(而不是半透明的灰色)。圓角組桌角上還有黑角。
任何想法,我要去哪裏錯了?
您的圖像是否已經透明?因爲如果沒有,你必須設置imageView alpha。 – 2011-03-25 11:03:27
圖像絕對透明。我在Photoshop中創建它,導出爲Web和設備並勾選'透明度'。 Finder的QuickLook中透明度顯示正常。 – Luke 2011-03-25 11:42:59