1

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

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

4

3 回答 3

5

您可以尝试将其添加到源代码中,我认为直接在情节提要中是不可能的:

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

self.tableView.backgroundView = tempImageView;
于 2013-06-07T02:27:11.887 回答
2

This is ggrana solution, but in Swift:

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

If so, vote up his solution in Obj-C

于 2016-02-05T10:47:58.980 回答
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 更改为您正在使用的图像的名称。

于 2013-06-07T03:03:41.607 回答