【问题标题】:Place a background Image behind a grouped UITableView将背景图片放在分组的 UITableView 后面
【发布时间】:2012-07-25 03:29:17
【问题描述】:

我有一个分组的 UITableView,它已经调整大小和四舍五入。我想在这张桌子后面放一个视图。我试过了:

[self.tableView addSubview:backgroundView];
[self.tableView sendSubviewToBack:backgroundView];

但它没有用。这是我得到的:

我想用背景代替黑色空间。

有什么想法吗?

【问题讨论】:

    标签: image uitableview uiview background behind


    【解决方案1】:

    [self.tableView setBackgroundView:backgroundView];怎么样?

    【讨论】:

    • 这里将图像作为 tableview 的背景(因此限制在分组表的区域内),而不是我需要在表后面有一个视图。
    • 我不清楚您所描述的差异。你的意思是像[self.tableView.superview addSubview:backgroundView]; ...;这样的东西吗?
    • 是的,我也在尝试,但它不起作用。变得非常疯狂。
    • 在这一点上,我不知道你需要什么样的外观才能称其为“工作”。 :)
    • 我已将您的代码放在 viewWillAppear: 和 viewDidLoad 中,但什么也没有 :(
    【解决方案2】:

    请耐心等待,我是初学者。我刚遇到这个问题,我找到了两个解决方案。就我而言,我使用的是 UITableView 对象。

    首先,将背景图片添加到应用的目录中。我把我的放在“支持文件”中

    您可以将图像添加为 UIColor 对象:

        ...
        [resultsTable setBackGroundColor:setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"background.jpg"]]];
        ...
    

    这个方法的问题是它会重复你的背景图像,因为它把它当作一个图案。

    更好的方法:

         // Create a string to store the path location of your image, otherwise you would have    to provide an exact path name
         NSString *backPath = [[NSBundle mainBundle] pathForResource:@"background"
         ofType:@"jpg"];
    
        // Create a UIImage Object to store the image.
         UIImage *bgImage = [[UIImage alloc ] initWithContentsOfFile:backPath];
    
         // Create a UIImageView which the TableView 
         UIImageView *bgView = [[UIImageView alloc]initWithImage:bgImage];
    
         // Set your TableView's background property, it takes a UIView Obj.
         [resultsTable setBackgroundView: bgView];
         .....
    

    【讨论】:

      猜你喜欢
      • 2011-08-15
      • 1970-01-01
      • 1970-01-01
      • 2018-08-10
      • 2018-02-18
      • 1970-01-01
      • 1970-01-01
      • 2019-06-20
      相关资源
      最近更新 更多