【问题标题】:tableViewheader transparent background becomes blacktableView header 透明背景变黑
【发布时间】:2012-01-03 20:54:49
【问题描述】:

我已经清除了 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;

【问题讨论】:

    标签: ios xcode uitableview png


    【解决方案1】:

    你试过了吗

    [tableView setBackgroundColor:[UIColor clearColor]];
    [tableView setBackgroundView:nil];
    

    【讨论】:

      【解决方案2】:

      尝试将headerView 的支持CALayercontents 设置为您的图像,而不是使用+colorWithPatternImage。对于这种方法,您需要链接并导入 <QuartzCore/QuartzCore.h>

      headerView.layer.contents = [UIImage imageNamed:@"headerBG"].CGImage;
      

      【讨论】:

        【解决方案3】:

        我试过你的代码,对我来说工作得很好。请再检查一次您的桌面视图。如果您仍然看到问题,请清理(shift+commond+K)它并再次编译它或再次检查您的图像。最后一个选项再次清除您的表格视图。

            tableView.backgroundColor = [UIColor clearColor];
        

        【讨论】:

          【解决方案4】:

          试过了吗???

          [tableView setBackgroundColor:[UIColor clearColor]];
          [tableView setBackgroundView:nil];
          

          在你的

          -(void)viewDidAppear{
           ....................
           ....................
          [tableview reloadData];
          }
          

          现在可能会起作用。

          【讨论】:

            【解决方案5】:

            在使用 [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];
            }
            

            【讨论】:

              猜你喜欢
              • 2023-03-17
              • 2011-12-27
              • 2013-11-25
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2015-10-23
              • 1970-01-01
              • 2016-02-22
              相关资源
              最近更新 更多