[英]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.