user1002909
user1002909

Reputation: 174

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

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

Upvotes: 2

Views: 1022

Answers (4)

Pradumna Patil
Pradumna Patil

Reputation: 2220

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];

Upvotes: 0

Pravin Tate
Pravin Tate

Reputation: 1130

UIView * separtor = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, 1)];
            separtor.backgroundColor = [UIColor whiteColor];
            [cell.contentView addSubview:separtor];

Upvotes: 1

Mithun Ravindran
Mithun Ravindran

Reputation: 2312

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.

Upvotes: 0

Randy
Randy

Reputation: 4525

Hi there,

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

Upvotes: 0

Related Questions