I have a UITableViewController. In viewDidLoad, I do the following:
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
The background is supposed to be a gradient. Two issues:
Gradient seems to get cut off at the end of the UITableView.
The corners are tinted.
I've experimented with setting the UITableCell's opacity to NO, but that doesn't worked. I have read these threads already: Transparent background in grouped UITableView - iPhone, and Black corners around UITableViewCells.
I'm not using Interface Builder at all for this.
Example:
Make a UIView with that pattern image as background color and set it as table view's background view.
UIView *bgView = [[UIView alloc] initWithFrame:self.tableView.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"bg_cafe.png"]];
self.tableView.backgroundView = bgView;
[bgView release];
Related
I have TableViewController with many cells. And background of my TableView Default White. I want to become some background image. I see this code :
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"BackgroundPattern.png"]];
but i can`t use this on swift. So help me recycle this code to swift code or give your solution to this problem
Try this code :
self.tableView.backgroundColor = UIColor(patternImage: UIImage(named: "BackgroundPattern.png")!)
You need to set the background colour of each cell to clear colour.
In your cellForRowAtIndexpath method, add: cell.backgroundColor = [UIColor clearColor]
UIColor *background = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:YOUR_IMAGE]];
self.tableView.backgroundColor = background;
or
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:YOUR_IMAGE]];
[imgView setFrame:self.tableView.frame];
self.tableView.backgroundView = imgView;
i have a problem in setting UITableViewCell background color. I wanna change it into my own color, so I use this code to change that background color :
UIView *bg = [[UIView alloc] init];
bg.backgroundColor = [ColorManager backgroundInput];
bg.layer.masksToBounds = YES;
[cell setSelectedBackgroundView:bg];
I implement this code in CellForRowAtIndexPath method.
The weird thing I have is, when i tap into a cell, the separator line color being highlight just like the image below. I just wanna make it still dark, anybody have idea?
Thank you
After setting up your own background view,which will have the line or not,
you can clear the default tableview color
tablename.separatorColor = [UIColor clearColor];
OR
If you don't want to remove the default line then you can give same color of background view to line color
//You can specify the RGB of background view
tablename.separatorColor = [UIColor colorWithRed:R green:G blue:B alpha:1.0f];
I think the best option is
[tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Another option is to set the backgroundColor of the UITableViewCell to a clear color.
cell.backgroundColor = [UIColor clearColor];
try it
Objective-c
tablename.separatorColor = [UIColor blackColor];
Swift
tablename.separatorColor = UIColor.blackColor();
I'm trying to put a background image into a UITableViewController with static cells inside.
Usually, in normal UIViewControllers I do this by changing the UIViewController's background color and setting the tableview's background color to clearcolor and opaque to NO
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"defaultBackground.png"]];
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
but doing this in my UITableViewController with static cell's leaves me with a transparent tableview with a black background. It seems like there is no view underneath.
I tried to add the view and make it contain the tableview, but this leaded to an empty view without the tableview.
self.view = [UIView alloc]initWithFrame:self.tableview.frame;
[self.view addSubview:self.tableView];
[self.view bringSubviewToFront:self.tableView];
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"defaultBackground.png"]];
self.tableView.opaque = NO;
self.tableView.backgroundColor = [UIColor clearColor];
Is there a way to fix this?
I've been trying to do this for a while now. I just want to remove the rounded corners you can see on this picture :
Does anyone know how to do it ?
[EDIT 1 : CELL BUILDING]
I am subclassing UITableViewCell to make my own layout. And then I'm adding a background to these cells like below :
UIImageView* imageView = [ [ UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320.0, 44.0)];
imageView.image = cellBackground;
cell.backgroundView = imageView;
I you need to edit the backgroundview of the corresponding cell. E.g.
UIView *bg = [[UIView alloc] initWithFrame:cell.frame];
bg.backgroundColor = [UIColor whiteColor]; // or any color
cell.backgroundView = bg;
[bg release];
The corners aren't rounded by default, just so you know.
Do you have a background image for the cell that makes the corners
seem rounded (most likely)?
Is each cell actually a section of the
tableview and there is no space between them?
Are you testing on a
jailbroken iPhone and you have some winterboard theme installed that
changes the style of tableviews?
I'm having an issue with UIImageView that's not quite making sense to me. I want to set the image of the UIImageView and have it appear above the patterned image I've set to the background. This occurs correctly if the background color is a standard color: [UIColor whiteColor], but as soon as set it to a patternImage the background becomes completely transparent. This is kind of frustrating. I can get around it by creating another view, setting the backgroundColor of it to a patternImage, and then adding the UIImageView as a subview, but that's creating an extra view that should be unnecessary, IMO. Here's my code:
UIImageView *view = [[UIImageView alloc] initWithFrame:_standardRect];
view.image = _connectIcon;
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.jpg"]];
view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
return view;
Doing this works on iOS 5.1:
view.layer.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed: #"background.jpg"]].CGColor;
However, the bug is gone on iOS 6.