【问题标题】:TableView with background image带背景图片的 TableView
【发布时间】:2012-06-05 11:14:01
【问题描述】:

我想在我的 tableview 后面有一个图像,我在后面添加了一个 UIImage 并将 tableview 背景设置为清除,在 IB 中它显示了 tableview 后面的图像但是当我运行它时我得到一个黑色背景,任何人都可以帮助我有了这个?

【问题讨论】:

  • 你想让背景滚动还是固定在tableview上?
  • 请确保您已将委托和数据源连接到 IBOutlet 中的 tableView !

标签: iphone ios uitableview uiimage


【解决方案1】:

取下图像并将此代码添加到您的 viewDidLoad:

UIView *patternView = [[UIView alloc] initWithFrame:self.tableView.frame];
patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.tableView.backgroundView = patternView;

这是添加固定图像作为表格视图背景的方法。

【讨论】:

  • 另一个简单的问题,我试图在 IB 中设置表格视图的位置,但它不起作用,你知道如何以编程方式执行此操作吗?
【解决方案2】:

或者你可以通过简单地在你的主控制器类中分配 tableview 的 backgroundView 属性来做到这一点而无需子类化......

【讨论】:

    【解决方案3】:

    -(void)viewDidLoad 方法中尝试以下代码

    self.tblView= [[UITableView alloc] initWithFrame:CGRectMake(17,110, 280.0, 265) style:UITableViewStyleGrouped];
        self.tblView.delegate=self;
        self.tblView.dataSource=self;
        //self.tblView.backgroundColor=[UIColor clearColor];
        self.tblView.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"img3.png"]];
        [self.view addSubview:self.tblView]; 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-11-17
      • 1970-01-01
      • 2017-05-28
      • 2015-11-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多