使用图像作为静态表视图的背景与故事板

时间:2013-06-07 02:16:41

标签: ios objective-c xcode uitableview

我正在创建一个没有故事板的tabbar应用程序,而是为我的一个标签创建了一个故事板。我有一个带静态表视图的UITableViewController。我也将它嵌入导航控制器中。由于它是一个静态表视图,我有segues指向不同的视图控制器。我没有链接到表视图的文件。我希望能够为表格视图设置背景图像。我已经尝试使用UIImageView并试图将它放在桌面视图后面,但故事板不会让我。有什么建议吗?

故事板图片:http://gyazo.com/b94987037a31d6164815790d90ba26d9

3 个答案:

答案 0 :(得分:5)

您可以尝试在源代码中添加它,我认为不可能直接在故事板中添加:

UIImageView *tempImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"YourImage.png"]];
[tempImageView setFrame:self.tableView.frame]; 

self.tableView.backgroundView = tempImageView;

答案 1 :(得分:2)

这是ggrana解决方案,但在Swift:

    let imvTableBackground = UIImageView.init(image: UIImage(named: "imgBackground"))
    imvTableBackground.frame = self.tableView.frame
    self.tableView.backgroundView = imvTableBackground

如果是这样,请在Obj-C中投票解决他的解决方案

答案 2 :(得分:1)

以下是可能对您有所帮助的代码段。您需要将图像添加为单元格内容。请尝试以下方法:

  - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
  cell = [CalculatorTableView alloc] initWithStyle:UITableViewStyleDefault  reuseIdentifier:nil]; //This wil obviously depend on your subclass
  UIImageView *backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Yourimage.png"]];
  [cell.contentView addSubview:backgroundView];
 }

将yourimage.png更改为您正在使用的图像的名称。

相关问题