iOS swift remove UITableView Cell separator space
In awakeFromNib
function setting UITableViewCell
options to UIEdgeInsetsZero
should work
self.layoutMargins = UIEdgeInsetsZero
self.separatorInset = UIEdgeInsetsZero
How to remove iOS TableView Separator
Ok I'm sorry, the problem was on my code, so you could not answer me ...
It was in my function : tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
Somewhere I wanted a border on my cell, so I have write:
var layer: CALayer = cell.layer
layer.borderColor = UIColor.rgbaColor(red: 288, green: 83, blue: 88, alpha: 1).CGColor
layer.borderWidth = 2
But this code didn't work because red:288 should be red:188, so I had a white border instead of an error, and I did not noticed ... Sorry for this, thanks a lot for your help :)
iOS 15: Remove empty space before cells in UITableView
Check if you are only seeing this issue on iOS 15 and above. If so, this may be caused by the newly introduced UITableView.sectionHeaderTopPadding
property. You will need to set this value to 0
in order to remove the spacing before section headings:
let tableView = UITableView()
tableView.sectionHeaderTopPadding = 0
// Etc.
This property is only available >= iOS 15 so you will need an API check if building for earlier versions.
If you're not on iOS 15, this question has most of the answers to this issue.
Remove UITableView separator line
Objective-C :
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
Swift:
self.tableView.separatorStyle = UITableViewCellSeparatorStyle.None
Swift 5.0 renamed it in :
self.tableView.separatorStyle = UITableViewCell.SeparatorStyle.none
Apply the line in viewDidLoad() method.
If you want to do it from nib file, set the tableView's Separator property to None
Eliminate extra separators below UITableView
Interface builder (iOS 9+)
Just drag a UIView to the table. In storyboard, it will sit at the top below your custom cells. You may prefer to name it "footer".
Here it is shown in green for clarity, you'd probably want clear color.
Note that by adjusting the height, you can affect how the "bottom bounce" of the table is handled, as you prefer. (Height zero is usually fine).
To do it programmatically:
Swift
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.tableFooterView = UIView()
}
Objective-C
iOS 6.1+
- (void)viewDidLoad
{
[super viewDidLoad];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [UIView new];
}
or if you prefer,
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
Historically in iOS:
Add to the table view controller...
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return CGFLOAT_MIN;
}
and if necessary...
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [UIView new];
// If you are not using ARC:
// return [[UIView new] autorelease];
}
How to remove cell separators in UITableView?
- Check your layout of cell,especially top and bottom constraints.
- Check the content view of cell.Did you set the clips to bounds to true?
All the above should be checked both in code and IB.
How to remove separator gap between UITableViewCells
First to explain how the separator works:
The separator is a subview of the cell, your content is usually inside the cell's content view.
To overlap the separator, you have two options:
Remove it completely using
table.separatorStyle = UITableViewCellSeparatorStyleNone
and add your own separator.If you want the image to overlap the separator, add it directly to the cell, not to the content view.
White space before separator line into my TableView
The leading whitespace is provided by default in iOS 7, even for custom cells.
Checkout this property separatorInset
of UITableviewCell to remove/add white spacing at either ends of cell's line separator.
// Remove white space
cell.separatorInset = UIEdgeInsetsZero;
Alternatively, at UITableView level, you can use this property -
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) { // Safety check for below iOS 7
[tableView setSeparatorInset:UIEdgeInsetsZero];
}
Update - Below code works on iOS 7 and iOS 8:
-(void)viewDidLayoutSubviews
{
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
Remove separator line for only one cell
On iOS 8 you need to use:
cell.layoutMargins = UIEdgeInsetsZero
If you want to be compatible with iOS 7 as well you should do following:
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
ADD: If previous didn't work - use this. (from answer below)
cell.separatorInset = UIEdgeInsetsMake(0, CGFLOAT_MAX, 0, 0);
If none of above worked, you can do:
self.tableView.separatorColor = [UIColor clearColor];
but this will leave 1 pixel empty space, not really removing a line, more making it transparent.
Related Topics
Type 'Any' Has No Subscript Members in Swift 3 Xcode 8
Storing a Variable When the App Is First Installed
Get the Exact Difference Between 2 Dates for a Single Nsdatecomponent
Which Passes How to Access in Apple Wallet
Swift - Set Delegate for Singleton
Create Alert Function in All View Controllers - Swift
Swift:How to Find the Position(X,Y) of a Letter in a Uilabel
How to Download and View Images from the New Firebase Storage
Live Render Iboutlet Connected Subviews via Ibinspectable Properties
Google Signin Cocoapods Deprecated
iOS Swift Avplayer Inside Uiview How to Make It Work
Swift App Crashes on Real Device But Works on Simulator
Animating Button Allowuserinteraction Not Working
Firebase: Provided Bucket Does Not Match the Storage Bucket of the Current Instance in Swift
Why Clusterannotationformemberannotations in Mkmapview Is Not Called
In Swift, for Anyobject, How to Setvalue() Then Call Valueforkey()