uitable裡的分割線,uitable分割線

來源:互聯網
上載者:User

uitable裡的分割線,uitable分割線

到了iOS8上,發現uitable是越來越不會用了;不說了,先看一下截屏效果:

設計期望的效果是:

1,自訂一個單元格,背景是黃色的;期望鋪滿整個表格單元;

2,單元分割線是貫通;


現實與理想的差別如下:

1,黃顏色單元格沒能橫向鋪滿整個單元;

2,分割線右側沒有拉到頭;

3,我只花了三個單元格;沒有充滿的空間,OS裡也畫上了分割線。


這是我的解決方案:

解決問題1的方式是:

設定table的邊距:[tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];

這是iOS8上新出的特性,所以這個問題在iOS7上沒有的。


解決問題2和3的方式是:

第一步:設定統一設定表格的分割線留空     [tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];

這裡設定分割線橫行留空1000個像素,這個的目的是為了讓所有的分割線畫到視圖之外,這樣子可以讓iOS自動補上的分割線都不可見了。


第二步:針對每個單元格設定留空:

    [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];

這樣可以讓我們需要的單元格分割線回到視圖中。


#import "ViewController.h"#import "DemoCell.h"@interface ViewController (){    IBOutlet UITableView *tableView;}@end@implementation ViewController- (void)viewDidLoad {    [super viewDidLoad];    // Do any additional setup after loading the view, typically from a nib.    //以下兩行為關鍵代碼<strong>    [tableView setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];    [tableView setSeparatorInset:UIEdgeInsetsMake(0, 1000, 0, 0)];</strong>        [tableView setSeparatorColor:[UIColor redColor]];}- (void)didReceiveMemoryWarning {    [super didReceiveMemoryWarning];    // Dispose of any resources that can be recreated.}- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{    return 3;}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{    DemoCell *cell =  (DemoCell*)[[[NSBundle mainBundle] loadNibNamed:@"DemoCell" owner:self options:nil] lastObject];        //以下兩行為關鍵代碼<strong>    [cell setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];    [cell setLayoutMargins:UIEdgeInsetsMake(0, 0, 0, 0)];</strong>    return cell;}@end


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.