IOS UITableView Split Line short 15 pixels, move to the leftmost method (IOS8)

Source: Internet
Author: User

Several friends asked me how to solve the iOS split-line, so I wrote a blog.
Why do I say 15 pixels less?
First we drag and drop a default TableView control! Look at the inspector of the Xcode5 Panel (inspector)
We can find a Separator insetss tag defaults to the default
We chose to find a custom at this time we are surprised to find that left 15, when we just change this 15 to 0, and then save, you will find the TableView line is the same as before.

Some friends asked if the code is written tableview.
Let's go on to analyze this problem and ask us to query the next TableView delegate we'll find that iOS7 adds some new properties,
@property (nonatomic) uiedgeinsets separatorinset Ns_available_ios (7_0) ui_appearance_selector;//allows Customization of the frame of cell separators

This time you should find out whether the word separatorinset is a bit familiar, Apple has given a comment, you can customize the View cell division line,
Uiedgeinsets is a struct type, and then we find the property we want left.
typedef struct UIEDGEINSETS {
CGFloat top, left, bottom, right; Specify amount to inset (positive) for each of the edges. Values can is negative to ' outset '
} uiedgeinsets;


Reprint
Now we can call this method in code,
[Mytableview setseparatorinset:uiedgeinsetsmake (0,0,0,0)];
At this point you will find your tableview line is not the same as before!

In iOS7, the left side of UITableViewCell will have a default 15 pixels blank. At this point, setting the Setseparatorinset:uiedgeinsetszero can remove the blanks.
But in iOS8, setting up Setseparatorinset:uiedgeinsetszero is no longer working. Here's the workaround
First, add the following code to the Viewdidload method:
if ([Self.tableview respondstoselector: @selector (setseparatorinset:)]) {
[Self.tableview Setseparatorinset:uiedgeinsetszero];
}
if ([Self.tableview respondstoselector: @selector (setlayoutmargins:)]) {
[Self.tableview Setlayoutmargins:uiedgeinsetszero];
}
Then add the following code to the UITableView proxy method
-(void) TableView: (UITableView *) TableView Willdisplaycell: (UITableViewCell *) cell Forrowatindexpath: (Nsindexpath *) Indexpath
{
if ([Cell respondstoselector: @selector (setseparatorinset:)]) {
[Cell Setseparatorinset:uiedgeinsetszero];
}
if ([Cell respondstoselector: @selector (setlayoutmargins:)]) {
[Cell Setlayoutmargins:uiedgeinsetszero];
}
}

Pro-Test: iOS8 and iOS9 are valid, there is a picture of the truth,.

The split line for IOS UITableView is 15 pixels short, moving to the leftmost method (IOS8)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.