【问题标题】:UItableview headerview with custom uiview?带有自定义uiview的UItableview headerview?
【发布时间】:2023-03-18 09:55:01
【问题描述】:

我正在创建一个自定义 uiview,其中包含一个 uilabel 和一个分配给 uiimageview 的 uiimage。我将自定义 uiview 分配给 uitableview headerview 但我只看到 uilabel 而不是 uiimage...请帮助这是我的代码...

UIView *containerView1 =[[UIView alloc]initWithFrame:CGRectMake(0, 0, 300, 30)];

UILabel *headerLabel1 =[[UILabel alloc]initWithFrame:CGRectMake(75, 4, 300, 20)];
    headerLabel1.userInteractionEnabled = YES;
    headerLabel1.text = [NSString stringWithFormat:@"- Latest update %@ -", now];
    headerLabel1.textColor = [UIColor brownColor];
    headerLabel1.shadowOffset = CGSizeMake(0, 1);
    headerLabel1.font = [UIFont boldSystemFontOfSize:13];
    headerLabel1.backgroundColor = [UIColor clearColor];

    UIImage *image = [UIImage imageNamed:@"line_seperator.png"];
    UIImageView *imageView = [ [ UIImageView alloc ] initWithFrame:CGRectMake(0.0, 0.0, 30, 30)];

    imageView.image = image;
    imageView.contentMode = UIViewContentModeScaleAspectFit;

    [containerView1 addSubview:headerLabel1];
   [containerView1 addSubview:imageView];
    [containerView1 addSubview:indicator2];

   walltable.tableHeaderView = containerView1;

任何帮助表示赞赏。

忘了说这段代码是在uitableview加载后执行的。

【问题讨论】:

  • 试试 self.tableView.tableHeadView = containerView1

标签: objective-c ios uitableview uiview


【解决方案1】:

我找到了。图像不对。该图像是从网上以 .gif 格式下载的。我在 Photoshop 中打开它并将其保存为 .png,但它没有正确保存。我在 Photoshop 中创建了一个新图像并复制了我在那个新图像中的那个。我将它保存为 .png 并且它有效。

【讨论】:

    猜你喜欢
    • 2016-12-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 2020-10-16
    • 1970-01-01
    相关资源
    最近更新 更多