iPhone Fixed-Position UITableView Background

后端 未结 5 1997
北海茫月
北海茫月 2020-12-03 14:53

I\'m building an iPhone app without the use of Interface Builder. I have set the background of a grouped UITableView in the following manor:

self.view.backgrou

相关标签:
5条回答
  • 2020-12-03 15:03

    use this below code in swift 3.0 to achieve constant background for tableview

     self.tableView.backgroundView = UIImageView(image: UIImage(named: "background.png")!)
    
    0 讨论(0)
  • 2020-12-03 15:12

    A little late but maybe for all the others looking for a solution. I could get that work by calling the parentViewController in the viewDidLoad method of the UITableViewController:

    self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"background.png"]];
    self.tableView.backgroundColor = [UIColor clearColor];
    

    or with using just a background color:

    self.parentViewController.view.backgroundColor = [UIColor scrollViewTexturedBackgroundColor];
    self.tableView.backgroundColor = [UIColor clearColor];
    

    It took me a while to figure that out but now it works like a charm.

    0 讨论(0)
  • 2020-12-03 15:13

    You can place an additional view below UITableView and set its background, so if UITableView is transparent - you'll achieve your goal - it will have correct background and it will not scroll.

    0 讨论(0)
  • 2020-12-03 15:17

    You can achieve a stationary background using a pattern image as follows:

    UIView *patternView = [[UIView alloc] initWithFrame:tableView.frame];
    patternView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"groupedBackground.png"]];
    patternView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    tableView.backgroundView = patternView;
    
    0 讨论(0)
  • 2020-12-03 15:19

    We find that it works exactly as you ask, if instead of using backgroundColor, you assign to backgroundView, like so:

    self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
                     [UIImage imageNamed:@"background.png"]];
    

    The table cells then scroll on top of the background, which is stationary. (This has been available since version 3.2 of the SDK, I believe.)

    0 讨论(0)
提交回复
热议问题