Iphone 设置分组UITableViewCell的背景色
我有一个表视图。我正在尝试创建自定义UITableViewCell背景:Iphone 设置分组UITableViewCell的背景色,iphone,objective-c,cocoa-touch,uitableview,Iphone,Objective C,Cocoa Touch,Uitableview,我有一个表视图。我正在尝试创建自定义UITableViewCell背景: - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { self.contentView.opaq
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.contentView.opaque = YES;
self.contentView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"rowbg@2x"]];
//Change Indicator
CGRect rect;
rect = CGRectMake(0, 0, 10, 50);
changeImageIndicator = [[UIImageView alloc] initWithFrame:rect];
[self.contentView addSubview: changeImageIndicator];
//Symbol
rect = CGRectMake(10, 10, 200, 20);
symbolLabel = [[UILabel alloc] initWithFrame:rect];
symbolLabel.textAlignment = UITextAlignmentLeft;
symbolLabel.font = [UIFont fontWithName:@"Arial" size:22];
symbolLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
symbolLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview: symbolLabel];
//Company
rect = CGRectMake(10, 30, 180, 20);
companyLabel = [[UILabel alloc] initWithFrame:rect];
companyLabel.textAlignment = UITextAlignmentLeft;
companyLabel.font = [UIFont fontWithName:@"Arial" size:13];
companyLabel.adjustsFontSizeToFitWidth = YES;
companyLabel.minimumFontSize = 10.0;
companyLabel.backgroundColor = [UIColor clearColor];
companyLabel.textColor = [UIColor colorWithRed:118.0/255.0 green:118.0/255.0 blue:118.0/255.0 alpha:1.0];
[self.contentView addSubview: companyLabel];
//Price
rect = CGRectMake(190, 10, 100, 20);
priceLabel = [[UILabel alloc] initWithFrame:rect];
priceLabel.textAlignment = UITextAlignmentRight;
priceLabel.font = [UIFont fontWithName:@"Arial" size:20];
priceLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
priceLabel.backgroundColor = [UIColor clearColor];
[self.contentView addSubview: priceLabel];
//Change
rect = CGRectMake(190, 30, 100, 20);
changeLabel = [[UILabel alloc] initWithFrame:rect];
changeLabel.textAlignment = UITextAlignmentRight;
changeLabel.font = [UIFont fontWithName:@"Arial" size:15];
changeLabel.textColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1.0];
changeLabel.adjustsFontSizeToFitWidth = YES;
changeLabel.backgroundColor = [UIColor clearColor];
changeLabel.minimumFontSize = 10.0; //adjust to preference obviously
[self.contentView addSubview: changeLabel];
}
return self;
}
背景色从圆角处溢出。如图所示:
我怎样才能让它不流血呢?这对我来说很有效,而其他什么都没有。将IB中的背景颜色设置为分组表视图颜色默认值。然后在代码中,将颜色设置为clearColor。我还将单元格标记为不透明=否和ClearContextBeforeDrawing=否,但这些设置本身并没有改变任何东西,直到我通过代码添加clearColor–Bdebeezself.tableView.separatorStyle=UITableViewCellSeparatorStyleNone self.contentView.superview.不透明=是;
self.contentView.superview.backgroundColor=[UIColor-WithPatternImage:[UIImage-ImageName:@rowbg@2x]]; 您是否尝试过设置backgroundView的backgroundColor而不是contentView?我必须创建一个圆形的顶部、中间和按钮图形图像,并根据单元格的行将其设置为单元格的背景视图。这适用于iOS 3.0及更高版本:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
cell.backgroundColor = [UIColor redColor];
}
在tableView:cellForRowAtIndexPath中设置单元格背景色:
我试着做下面的事情,我希望UITableView的背景色是条纹色。所以这是行不通的。我甚至试过用清晰的颜色,结果是一样的。我不知道怎么做,但你可以用条纹图像替换条纹颜色。使用分隔样式的图像仍然不走运。这也有同样的结果
cell.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Gradient.png"]];