开发者

UIView background transparency

I add UIView with background image(that has transparent parts) into the UITableViewCell. At first everything looks perfect, but after deselecting row, background of my UIView looses transparency.

step 1

http://img29.imageshack.us/img29/1842/screenshot20110910at409.png

开发者_开发问答step 2

http://img41.imageshack.us/img41/1842/screenshot20110910at409.png

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

UIView *priceView = [[UIView alloc] init];
priceView.frame = CGRectMake(250, 10, 40, 21);

priceView.backgroundColor = [UIColor colorWithPatternImage:[ UIImage imageNamed:@"priceBG.png" ]];
priceView.opaque = NO;
[priceView.layer setOpaque:NO];
[cell addSubview:priceView];
[priceView release];
return cell;


Use a UIImageView instead and add it to the cell's contentView:

static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}

UIImageView *priceImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"priceBG.png" ]];
priceImageView.frame = CGRectMake(250, 10, 40, 21);
priceImageView.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:priceImageView];
[priceImageView release];    
return cell;


I am not sure whether i am answering your question or not but to set background of tableViewCell check out following tow properties of cell.

  1. backgroundView
  2. selectedBackgroundView

If your purpose is not to give background to cell then use UIImageView and set it as subView in contentView if cell.

It seems that you problem is with cell selection style. check selectionStyle property here. Assigning a proper background view will help you to remove that blue color.

Following is link to class reference.

http://developer.apple.com/library/ios/#documentation/UIKit/Reference/UITableViewCell_Class/Reference/Reference.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜