`
auauau
  • 浏览: 168446 次
社区版块
存档分类
最新评论

UITableViewCell 间隔颜色

    博客分类:
  • iOS
 
阅读更多
- (UITableViewCell *)tableView:(UITableView *)mtableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
	NSInteger row = [indexPath row];
	static NSString *CellIdentifier = @"cai-sflist-cell";
	
	UITableViewCell *cell = (UITableViewCell*)[mtableView dequeueReusableCellWithIdentifier:CellIdentifier];
	if (!cell){
		cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
	}
	NSDictionary *caiDictionary = [list objectAtIndex:row];

	UIView *v = [[UIView alloc] initWithFrame:cell.frame];
	if(row % 2 ){
		v.backgroundColor = [UIColor whiteColor];
	}else{
		UIColor *backgroundColor = [UIColor colorWithRed:(251.0/255.0) green:(248.0/255) blue:(243.0/255) alpha:1.0];
		v.backgroundColor = backgroundColor;
	}
	cell.backgroundView = v;
	[v release];

	cell.textLabel.text = [caiDictionary objectForKey:@"english"];
	cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
	
	return cell;
}


- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
	cell.backgroundColor = [UIColor clearColor];
}
分享到:
评论
1 楼 asm 2011-01-28  
- (void)setUseDarkBackground:(BOOL)flag {
    if (flag != useDarkBackground || !self.backgroundView)
    {
        useDarkBackground = flag;

        NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:useDarkBackground ? @"DarkBackground" : @"LightBackground" ofType:@"png"];
        UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
        self.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
        self.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        self.backgroundView.frame = self.bounds;
    }
}


cell.useDarkBackground = (indexPath.row % 2 == 0);
和楼主道理一样,如果使用backgroundColor没用

相关推荐

Global site tag (gtag.js) - Google Analytics