读书人

UITableViewCell 间距颜色

发布时间: 2012-09-20 09:36:50 作者: rapoo

UITableViewCell 间隔颜色

- (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];}
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没用

读书人网 >移动开发

热点推荐