Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 448 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
iOS 8 UITableView separator inset 0 not working

#21
Adding this snippet, simple elegant in Swift works for me in iOS8 :)

// tableview single line
func tableView(tableView: UITableView, willDisplayCell cell: UITableViewCell, forRowAtIndexPath indexPath: NSIndexPath) {
cell.preservesSuperviewLayoutMargins = false
cell.layoutMargins = UIEdgeInsetsZero
}
Reply

#22
> Swift 2.0 Extension
> -------------------

I just wanted to share an extension I made to remove the margins from the tableview cell separators.

extension UITableViewCell {
func removeMargins() {

if self.respondsToSelector("setSeparatorInset:") {
self.separatorInset = UIEdgeInsetsZero
}

if self.respondsToSelector("setPreservesSuperviewLayoutMargins:") {
self.preservesSuperviewLayoutMargins = false
}

if self.respondsToSelector("setLayoutMargins:") {
self.layoutMargins = UIEdgeInsetsZero
}
}
}

**Used in context:**

let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath) as! CustomCell

cell.removeMargins()
return cell
Reply

#23
For iOS 9 you need to add:

if([myTableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)])
{
myTableView.cellLayoutMarginsFollowReadableWidth = NO;
}

For more details please refer to [question](

[To see links please register here]

).
Reply

#24
This worked perfectly for me in iOS 8 and iOS 9.

For **OBJ-C**

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
if ([tableView respondsToSelector:@selector(setSeparatorInset:)])
{
[tableView setSeparatorInset:UIEdgeInsetsZero];
}

if ([tableView respondsToSelector:@selector(setLayoutMargins:)])
{
[tableView setLayoutMargins:UIEdgeInsetsZero];
}

if ([cell respondsToSelector:@selector(setLayoutMargins:)])
{
[cell setLayoutMargins:UIEdgeInsetsZero];
}
return cell;
}

Reply

#25
following answer from @cdstamper, a better place is layoutSubviews of UITableViewCell, in your cell file(I set 1% spacing, you can set to zero), so need only to set code here to handle all situations(rotate and other):


-(void)layoutSubviews
{
[super layoutSubviews];
if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
[self setSeparatorInset:UIEdgeInsetsMake(0,self.bounds.size.width*0.01,0,self.bounds.size.width*0.01)];
}
if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
[self setLayoutMargins:UIEdgeInsetsMake(0,self.bounds.size.width*0.01,0,self.bounds.size.width*0.01)];
}
}
Reply

#26
Here's an easy way to globally remove the inset.

In `UITableViewCell+Extensions.swift`:

import UIKit

extension UITableViewCell {

override public var layoutMargins: UIEdgeInsets {
get { return UIEdgeInsetsZero }
set { }
}

}

In `AppDelegate` `application:didFinishLaunchingWithOptions:`:

UITableViewCell.appearance().separatorInset = UIEdgeInsetsZero

You might think to a) also just override `separatorInset` in the extension, or b) set the appearance proxy for `layoutMargins`, instead. Neither will work. Even though `separatorInset` is indicated to be a property, attempting to override it as a property (or method) generates compiler errors. And setting the appearance proxy for `UITableViewCell`'s `layoutMargins` (or, for that matter, also setting the appearance proxies for `UITableView`'s `layoutMargins` and `separatorInset`) has no effect.
Reply

#27
XCode 7.1 iOS 7, 8, 9:

just put these two lines in your TabelViewCell:

self.layoutMargins = UIEdgeInsetsZero;
self.preservesSuperviewLayoutMargins = false;

That worked for me

Reply

#28
My solution is adding an UIView as a container for the cell subviews. Then set this UIView constraints (top,bottom,trailing,leading) to 0 points. And all the unnecessary mass go away.[the image showing the logic][1]


[1]:
Reply

#29
This is my solution. This applies to the custom cell subclass, just add them both to the subclass.

1.

- (UIEdgeInsets)layoutMargins {
return UIEdgeInsetsMake(0, 10, 0, 10);
}

2.

self.separatorInset = UIEdgeInsetsMake(0, 10, 0, 10);

And it is convenient that you can customize the position of the separator without asking your designer to draw one for you..........
Reply

#30
For me the simple line did the job

cell.layoutMargins = UIEdgeInsetsZero
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through