UITableView的分割線長短的控制,uitableview長短

來源:互聯網
上載者:User

UITableView的分割線長短的控制,uitableview長短

UITableView的預設的cell的分割線左邊沒有頂滿,而右邊卻頂滿了。這樣顯示很難看。我需要讓其左右兩邊都是未頂滿狀態,距離是20像素

 

// code1    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {        [self.tableView setSeparatorInset:UIEdgeInsetsMake(0, 20, 0, 20)];    }// code2     if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0, 20, 0, 20)];    }

 

添加UITableView的一個代理方法:

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{    if ([cell respondsToSelector:@selector(setSeparatorInset:)])    {        [cell setSeparatorInset:UIEdgeInsetsMake(0, 15, 0, 15)];    }    if ([cell respondsToSelector:@selector(setLayoutMargins:)])    {        [cell setLayoutMargins:UIEdgeInsetsMake(0, 15, 0, 15)];    }}

 

ode1處代碼: 
定製cell分割線的frame

code2處代碼: 
-layoutMargins returns a set of insets from the edge of the view’s bounds that denote a default spacing for laying out content. 
If preservesSuperviewLayoutMargins is YES, margins cascade down the view tree, adjusting for geometry offsets, so that setting the left value of layoutMargins on a superview will affect the left value of layoutMargins for subviews positioned close to the left edge of their superview’s bounds 
If your view subclass uses layoutMargins in its layout or drawing, override -layoutMarginsDidChange in order to refresh your view if the margins change.

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.