How to set UITableView background for image?

I noticed that a number of applications have a custom background image for a UITableView (or set the background to color.)

I cannot find any API in the UITableView class to affect this, and my attempts at the interface builder failed (trying to set the color of the UIView)

Any suggestions? I saw a third-party application with photos, so I know that this can be done.

+3
source share
8 answers

add this line to the code where you want to set the background color for your image

[ViewView (or ImageView) property setbackgroundColor: [UIColor groupTableViewBackgroundColor]];

thank

+2
source

, , TomSwift. , UITableView backgroundView, , , . , backgroundColor, . :

// Set an image as the background of a UITableView called 'tableView'
UIImageView *bg = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"MyImage.png"]];
[tableView setBackgroundView:bg];

// Set a solid color as the background of a UITableView called 'tableView'
// In this case I chose red
[tableView setBackgroundColor:[UIColor redColor]];
+15
UIImageView *image = [[UIImageView alloc] initWithImage:
                                    [UIImage imagenamed:@"no_image.png"]];
[self.view addSubview:image];
UITableView *tableview = [[UITableView alloc] init];
[image addSubview:tableview];
tableview.backgroundcolor = [UIColor clearColor];
+2

. .

CALayer *background = [CALayer layer];
background.zPosition = -1;
background.frame = self.view.frame;
background.contents = [[UIImage imageNamed:@"background.jpg"] CGImage];
[tableView.layer addSublayer:background];
+2
+1

backgroundView View. , backgroundColor, UIImageView, .

0

GhostRider

To make UiImageView an interface constructor, put your image in resources. set it in the UIImageView Image property using the Inspector. select the table view and set the background color for cleaning (to do this, make the opacity 0 using the attribute inspector).

0
source

Here is how I did it. This is probably not the best way, but it works quite well.

UIImage *bg = [UIImage imageNamed:@"bg"];
[bg drawInRect:self.view.window.frame];
UIImageView *bgView = [[UIImageView alloc] initWithFrame:self.view.window.frame];
bgView.image = bg;

activityTable.backgroundView = bgView;  //activityTable = UITableView
0
source

Source: https://habr.com/ru/post/1777837/


All Articles