I have subclassed the UITableView control, and the style is grouped, but I do not need the cell separators. I tried setting my table view's separatorStyle to none, but it doesn't work. Can any one help me out?
In a grouped table view, setting separatorStyle doesn't do anything. If you want to hide it, just do the following:
tableView.separatorColor = [UIColor clearColor];
Use this
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
To remove the border of a table view write this line:
self.myTableView.separatorColor = [UIColor clearColor];
If you want to remove both the border of a table view but the border between cells too, you have to write both lines:
self.myTableView.separatorColor = [UIColor clearColor];
self.myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
This did the trick for me:
[dayTableView setSeparatorColor:[UIColor whiteColor]]; //or your background color
swift 4 use
myTableView.separatorStyle = UITableViewCellSeparatorStyle.none
How about setSeparatorColor to your cell's background color?
Related
I want to get rid of this white border or colorize it to black.
As you see on the image, i want to change the white borders those shown in red circles.
How can i change it?
after adding this cote to tableview controller's viewDidLoad method;
[self.tuzukCell.contentView.layer setBorderColor:[UIColor blackColor].CGColor];
[self.tuzukCell.contentView.layer setBorderWidth:2.0f];
the resulting border is:
for static cell.. all of these methods .. must be setup in the storyboard file..
so..
click on storyboard file / Table view / Separator "none" / and choose desired color..
UITableViewCell contentView's underlying CALayer
Firstly import QuartzCore
#import <QuartzCore/QuartzCore.h>
Add this in cellForRowAtIndexPath in UITableView delegate method
[cell.contentView.layer setBorderColor:[UIColor blackColor].CGColor]; //any color u want to....
[cell.contentView.layer setBorderWidth:2.0f]; //set its width here
EDIT :Use this property according to requirement if tableview is static:
separatorStyle property
separatorColor property
backgroundView property
In CellForRowAtIndexPath, try this (after you init your cell) :
cell.layer.borderColor = [UIColor blackColor].CGColor;
Of course you can change blackColor to any other UIColor.
You can also do :
cell.layer.borderWidth = 0;
If you just wan to hide it.
the following code will change the separator color, which means that it will change the separator line between the cell and the border itself.
try this to change it to black:
tableView.separatorColor = [UIColor blackColor];
or to remove it:
tableView.separatorColor = [UIColor clearColor];
Hi can any one tell me how can i remove the black edges at the corner of mY UITableView GroupStyle. i have create a custom view for my UITableView Cell. i have tried this code but it work in IOS 5 and not work in IOS 4.0 what the problem is that i have tried all the proposed solution Please Help! self.tableView = [UIColor ClearColor]; in viewDidLoad work in Ios 5 not in IOS 4 what problem is that . when i run this on simulator 5.1 then it not show black edges but show black edges in simultor 4.3. Please Help
To remove the borders from the cells:
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
In code:
tableView.backgroundView = nil;
And if you putting table through xib :
Make SeparatorStyle = Single Line
thank you all for helping me.
Actually this work for me
self.tableView backgroundcolor = [UIColor ClearColor];
but i was missing the IBOutlet of tableView so i connect the property of tableview with interface Builder it work for me!
I replaced the tableView's backgroundView with a new view.
I then relied on the tableView's backgroundColor property to set the color I wanted:
self.tableView.backgroundView = [[[UIView alloc] init] autorelease];
self.tableView.backgroundColor = [UIColor whiteColor];
I need to set the background of table cells to a specific color.
(#222222 or RGB(32,32,32) respectively)
The background of the table view in IB is set properly. The correct gray appears in the back of the table header and in section headers etc.
But I struggle with the cells.
To customize the cell's apperance I subclass UITableCell and implement the layoutSubviews method.
This works fine:
- (void)layoutSubviews {
[super layoutSubviews];
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.backgroundColor = [UIColor darkGrayColor];
self.contentView.backgroundColor = [UIColor darkGrayColor];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor grayColor];
}
However, grayColor and darkGrayColor simply do not match the colour that I need.
Naturally I tried the colorWithRed:green:blue:alpha method of UIColor.
- (void)layoutSubviews {
[super layoutSubviews];
self.selectionStyle = UITableViewCellSelectionStyleGray;
self.backgroundColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
self.contentView.backgroundColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
self.textLabel.textColor = [UIColor whiteColor];
self.detailTextLabel.textColor = [UIColor colorWithRed:(32/256) green:(32/256) blue:(32/256) alpha:1];
}
That one results in black background and black color of the detailTextLable.
(Of course it is senseless using the same color for a background and for a text label. I am just trying to work out what colorWithRed:green:blue:alpha does and does not.)
With plain style tables I am fine. Those' cells do not have a background color at all. When I just omit setting the backgroundColor and the contentView's background Color propierties then the background of the cells is displayed as defined as the Table's background color in IB.
But with grouped tables the standard background is some light gray which I want to change to some more decent color that matches my client's style guide.
What am I doing wrong? Do I use colorWithRed:green:blue:alpha properly?
Any suggestion is much appreciated.
I would try an other methods of calucaluting the color float:
[UIColor colorWithRed:(32.0f/255.0f) green:(32.0f/255.0f) blue:(32.0f/255.0f) alpha:1.0f];
since 0 is also include you have 0 to 255 values not 1 to 256 values.
If you want the cell to be transparent use [UIColor clearColor]
32/256 = 0 but 32/256.0 = 0.125.
Thanks for putting your finger to the error.
However, this does not exactly answer the question related to the difference between plain and grouped table style.
Just in case somebody finds the question interesting:
The grouped style comes with a background view. I set that to nil.
The gropued style always has a cell background color set to something. Therefore omitting the self.backgroundColor=... statement was not sufficient.
finally
self.backgroundColor = [UIColor clearColor];
did the trick. It was just not remotely connected to the objective-c mistake that I made too.
I use a grouped tableview and custom cells which I load from nib. When I set the background colour of tableview to clearcolor then I can only see the contents of the cells but nothing about the tableview. I like the rounded corners and seperator lines of the gropued view, so I want to keep those lines and change the colours of the lines, but set the table's background colour transparent so I will see the main image of the window. is this possible?
So you wanted to change the color of separator lines
self.tableView.separatorColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:1];
// give your hex color code or your color
Inside of viewDidLoad of your view controller you need to set the backgroundView to nil and the backgroundColor to clear.
self.tableview.backgroundView = nil;
self.tableview.backgroundColor = [UIColor clearColor];
I've seen some iPhone applications that use a custom image as the background for a grouped UITableView, instead of the standard gray lines.
How is this achieved?
Here's what worked for me (and fairly simple once I figured it out ;)
1) Add a view in your app delegate and make it a subview of the window:
UIView *bgView = [[UIView alloc]initWithFrame:window.frame];
bgView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"screenBG.png"]];
[window addSubview:bgView];
[bgView release];
2) On each view controller .m file, under ViewDidLoad, set background color of that particular view to transparent (so the other bgView created above will show through):
self.view.backgroundColor = [UIColor clearColor];
And in my case, the view controller in step 2 was a tableviewcontroller. Looks great.
And BTW, doing the following in each view controller did NOT work well:
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"screenBG.png"]];
So follow steps 1 and 2 above.
Hope this helps out,
Tbone
Try this
- (void) viewDidLoad {
[super viewDidLoad];
self.tableView.backgroundColor = [UIColor clearColor];
self.view.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:#"wallpaper.png"]];
self.tableView.opaque = NO;
}
In another project (developed using 2.2.1) I did this by setting my UITableView's background opacity to 0%, and then simply layering a UIImageView behind it using Interface Builder. This allowed me to have a fixed background regardless of the table state. You can also set the background of the UITableView to be an image instead, but then the background scrolls with the table. (I don't have the code handy at the moment, but I got the tip a while back on the Apple developer forums).
Note that this can cause some performance issues. Apple discourages using transparency whenever possible because the GPUs on the pre-3GS models aren't particularly beefy.
You can use the +[UIColor colorWithPatternImage:(UIImage)] method like so:
self.tableView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Background.png"]];
the problem with colorWithPatternImage: is that you need to use "patterned" images, otherwise your image will be tiled randomly
this link has a simple solution, if you want all your views to have the same background
http://howtomakeiphoneapps.com/2009/03/how-to-add-a-nice-background-image-to-your-grouped-table-view/
self.parentViewController.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"SortByCategory_320x480.png"]];
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.backgroundColor = [UIColor clearColor];
Hope this will help. It won't display hideous translucent background behind the cells especially in case of Grouped UITableView.