Are there any way to make a separator view like UITableView's separator?

1k Views Asked by At

I want to custom the separator line view like that, but I'm still stuck here. Facebook app make the separator line view is a good looking. I want to archive something like that. Can any one help me?

I try with set frame and update constraint, but it does not work on all devices (iPhone 4s, iPhone 5, iPhone 6, iPhone 6 Plus).

I use both constraints and custom frame for UIView to make it works like a separator line view, the height is 0.5 for constraint's constant or frame's height. But it does not like the UITableView separator. The height is not really thin like Facebook app does and sometimes it does not show.

Thanks

4

There are 4 best solutions below

0
On

Hi there,

You can still add a really thin and empty UIView with a background color you desire.

3
On

Create a custom cell / Prototype cell and design it according to the requirement.

At the bottom of the designed custom cell, add a view(with minimum constant height) and set its size colour and other parameters according to the UI need.

Set constraint to it (Prefer giving predefined height to the separator view) so that visual will be same and adopt the width for different devices.

Finally, remove the default separator which will be set by the table view.

i.e: Set 'separator' property to 'None' for table view.

1
On

Try this

UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 3)];/// change size as you need.       
 separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
 [cell.contentView addSubview:separatorLineView];

Hope it helps

CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;


UIView* separatorLineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 3)];/// change height as you need.       
 separatorLineView.backgroundColor = [UIColor whiteColor];// you can also put image here
 [cell.contentView addSubview:separatorLineView];
0
On
UIView * separtor = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 1)];
            separtor.backgroundColor = [UIColor whiteColor];
            [cell.contentView addSubview:separtor];