Is there a way to make UITableView cells in iOS 7

2019-01-04 07:01发布

I noticed that in iOS 7, UITableViewCells have a line break in the separator of the cell that iOS 6 does not have. Is there a way to get rid of this line break? Changing the separator to none and then making UIViews with the color of the separator still causes the white separator to occur regardless.

17条回答
疯言疯语
2楼-- · 2019-01-04 07:33

Figured it out.

[self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
查看更多
来,给爷笑一个
3楼-- · 2019-01-04 07:33
@implementation UITableView (HGApperance) 
-(void)setSeparatorXMargin:(CGFloat)margin{
    // iOS 7
    if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
        [self setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([self respondsToSelector:@selector(layoutMargins)]) {
        self.layoutMargins = UIEdgeInsetsZero;
    }
}
@end

For TableviewCell, Willam's answer works perfect.

查看更多
Melony?
4楼-- · 2019-01-04 07:33

Xamarin.iOS Version

I extended the UITableView separator the full width in Xamarin.iOS on iOS 8.4 with help from posts by Luis E. Prado and King-Wizard. I had to set both SeparatorInset and LayoutMargins to get it working. I did not write checks for lower iOS versions since I am targeting iOS 8 and above.

I wrote the following two C# extension methods to set the UITableView separator full width at the UITableView or UITableViewCell level. You might use one or both of these methods depending on the desired effect (see the explanations below).

UITableView

Set the UITableView properties to alter the separators that appear after empty cells. This SetLayoutMarginsZero method could be called from the related ViewController's ViewDidLoad method.

public static void SetLayoutMarginsZero(this UITableView tableView)
{
    tableView.SeparatorInset = UIEdgeInsets.Zero;
    tableView.LayoutMargins = UIEdgeInsets.Zero;
}

UITableViewCell

Set the UITableViewCell properties to alter the separators that appear after populated cells. This SetLayoutMarginsZero method could be called from the TableViewSource GetCell method.

public static void SetLayoutMarginsZero(this UITableViewCell tableViewCell)
{
    tableViewCell.SeparatorInset = UIEdgeInsets.Zero;
    tableViewCell.LayoutMargins = UIEdgeInsets.Zero;
    tableViewCell.PreservesSuperviewLayoutMargins = false;
}
查看更多
The star\"
5楼-- · 2019-01-04 07:34

If you want to support older versions of iOS, you should check for the availability of this method before calling it:

if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
查看更多
乱世女痞
6楼-- · 2019-01-04 07:34

Beware as setting the separatorInset of tableView to UIEdgeInsetsZero seems to break the left margin of section titles at the same time! (at least it does on iOS 7.1)

If you want to display section titles with tableView:titleForHeaderInSection: and still get the desire effect of no line break between UITableViewCells, you must set the separatorInset directly on the cells instead of the tableView!

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // ...
    [cell setSeparatorInset:UIEdgeInsetsZero];
查看更多
我命由我不由天
7楼-- · 2019-01-04 07:37
- (void)viewDidLoad
{
    [self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];

    [super viewDidLoad];

    // Additional setup
}

Note: the setSeparatorStyle line has to be above the super call.

查看更多
登录 后发表回答