通过tableHeaderView,UITalbleView,ios看不到图像

时间:2013-05-10 20:14:11

标签: ios objective-c uitableview

我试图通过以下

通过tableHeaderView查看我的图像
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UIView *tableHeaderView         =   [[UIView alloc] initWithFrame: CGRectMake(0.0, 0.0, self.view.frame.size.width, 180.0)];
    tableHeaderView.backgroundColor =   [UIColor clearColor];
    UIView *blackBorderView         =   [[UIView alloc] initWithFrame: CGRectMake(0.0, 179.0, self.view.frame.size.width, 1.0)];
    blackBorderView.backgroundColor =   [UIColor colorWithRed: 0.0 green: 0.0 blue: 0.0 alpha: 0.8];
    [tableHeaderView addSubview: blackBorderView];

    self.tableView.tableHeaderView  =   tableHeaderView;
    self.tableView.tableHeaderView.backgroundColor  =   [UIColor clearColor];



    _headerImageYOffset             =  0;
    _headerImage                    =  [[UIImageView alloc] initWithImage: [UIImage imageNamed: @"myImage.png"]];
    CGRect headerImageFrame         =  _headerImage.frame;
    headerImageFrame.origin.y       =  _headerImageYOffset;
    _headerImage.frame = headerImageFrame;
    [self.view insertSubview: _headerImage belowSubview: self.tableView];

}

但是,根本看不到图像。我认为clearColor可以帮助我看到图像。

如果我在xib中修改ny表视图的位置并运行代码,我可以看到部分图像

enter image description here

如果您对此有任何想法,请帮助

1 个答案:

答案 0 :(得分:0)

表的背景不透明,请尝试

[self.tableView setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0 ]];