Reputation: 7060
In iOS 7 , default UITableViewCell
separator
is a little bit cutting from left that can show cell's imageView
.
I can change to full size with following codes.
[self.tableViewMain setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
And i want to change it when my iPad orientation is Portrait.
So i tried following codes in rotate event
if(UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ||(UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation)))
{
[self.tableViewMain setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
}
else
{
[self.tableViewMain setSeparatorInset:UIEdgeInsetsMake(15, 0, 0, 0)];
}
I want to do it like iOS7 Cell Separator manually.
How can i do it?
Upvotes: 0
Views: 12597
Reputation: 258
You should negative value in the place of left inset
self.tableView.separatorInset = UIEdgeInsetsMake (0, -15, 0,0);
Upvotes: 1
Reputation: 4244
Here you go.
[self.tableViewMain setSeparatorInset:UIEdgeInsetsMake(15, 0, 0, 0)];
EDIT:
Above answer is wrong. Adding a custom UIView
will solve this.
Your cellForRowAtIndexPath
should be lie this
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
UIView *lineView;
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
lineView = [[UIView alloc] initWithFrame:CGRectMake(15, cell.contentView.frame.size.height - 1.0, cell.contentView.frame.size.width, 1)];
[cell.contentView setFrame:CGRectMake(0, 0, cell.contentView.frame.size.width, cell.contentView.frame.size.height-1)];
[cell.textLabel setBackgroundColor:[UIColor clearColor]];
lineView.backgroundColor = [UIColor darkGrayColor];
[cell.contentView addSubview:lineView];
[lineView release]; // IGNORE IF USING ARC
}
[cell.textLabel setText:@"YOUR_TEXT"];
return cell;
}
Upvotes: 2
Reputation: 4551
You mean by manually Interface Builder ? if it's the case, click your UITableViewCell in IB and go to the third panel, in Separator insets choose custom and you can put the left and right value.
Edit : if you want to do it by code, see the documentation of UIEdgeInsets structure : UIEdgeInsets Defines inset distances for views.
typedef struct {
CGFloat top, left, bottom, right;
} UIEdgeInsets;
Then for example :
self.tableViewMain.separatorInset = UIEdgeInsetsMake (0, 15, 0,0);
Upvotes: 11