[英]tableViewheader transparent background becomes black
我已经清除了tableview的背景。 现在,我创建了具有透明背景的PNG图像,并将其设置为tableViewHeader的backgroundView。
PNG的透明背景在tableViewHeader中以某种方式变为黑色。 有人有什么线索吗?
谢谢。
//Header Layout
UIView *headerView =
[[[UIView alloc]
initWithFrame:CGRectMake(0, 0, 300, 70)]
autorelease];
UILabel *headerLabel =
[[[UILabel alloc]
initWithFrame:CGRectMake(10, 10, 300, 40)]
autorelease];
headerView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"headerBG.png"]];
headerLabel.text = NSLocalizedString(@"Huidig", @"");
headerLabel.textColor = [UIColor redColor];
headerLabel.shadowColor = [UIColor greenColor];
headerLabel.shadowOffset = CGSizeMake(0, 1);
headerLabel.font = [UIFont boldSystemFontOfSize:22];
headerLabel.backgroundColor = [UIColor clearColor];
[headerView addSubview:headerLabel];
tableView.tableHeaderView = headerView;
你有没有尝试过
[tableView setBackgroundColor:[UIColor clearColor]];
[tableView setBackgroundView:nil];
使用[UIColor colorWithPatternImage:]为UILabel提供背景图像时,我遇到了类似的问题。 运行4.2.1(iPhone 3G)的设备将图像的透明部分显示为黑色。 我尝试过更改opaque属性,并将图像设置为图层,但两者均无效。
相反,我实现了一个继承UILabel的新类,并在drawRect中仅绘制了图像:
- (void)drawRect:(CGRect)rect
{
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextClearRect(context, rect);
UIImage *image = [UIImage imageNamed:@"graphics/pricetag.png"];
CGContextDrawImage(context, rect, image.CGImage);
// Have UILabel draw the text
[super drawRect:rect];
}
我尝试了您的代码,对我来说绝对不错。 请再检查一次tableview。 如果仍然发现问题,请清洁(shift + commond + K)并重新编译一次,或再次检查图像。 最后选择清除您的表视图一次。
tableView.backgroundColor = [UIColor clearColor];
而不是使用+colorWithPatternImage
尝试将headerView
的支持CALayer
的contents
设置为图像。 您需要针对此方法链接并导入<QuartzCore/QuartzCore.h>
。
headerView.layer.contents = [UIImage imageNamed:@"headerBG"].CGImage;
尝试过了吗???
[tableView setBackgroundColor:[UIColor clearColor]];
[tableView setBackgroundView:nil];
在你的
-(void)viewDidAppear{
....................
....................
[tableview reloadData];
}
也许现在可以正常工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.