繁体   English   中英

使用图像作为背景与情节提要的静态表格视图

[英]Using image as background for static table view with storyboards

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

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

您可以尝试在源中添加它,我认为不可能直接在情节提要中添加它:

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

self.tableView.backgroundView = tempImageView;

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

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

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

这是一个可以帮助您的代码段。 您需要添加图像作为单元格内容。 请尝试以下操作:

  - (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更改为您正在使用的图像的名称。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM