iOSのUITTable Viewell cellの線を引くということは韓俊強のブログです.


毎日更新のご注意:http://weibo.com/hanjunqiang 
開発において、常にセル分割線の表示が不完全またはカスタムラインの幅が高いということがあります.最近まとめましたが、皆さんにお願いします.
1.線を引きたくないですが、どうすればいいですか?
TableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; //           
-(void)viewDidLayoutSubviews {

    if ([TableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [TableView setSeparatorInset:UIEdgeInsetsZero];

    }
    if ([TableView respondsToSelector:@selector(setLayoutMargins:)])  {
        [TableView setLayoutMargins:UIEdgeInsetsZero];
    }

}

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPat{
    if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
    if ([cell respondsToSelector:@selector(setSeparatorInset:)]){
        [cell setSeparatorInset:UIEdgeInsetsZero];
    }
}
毎日更新のご注意:http://weibo.com/hanjunqiang 
2.線を引いて設定したいですが、どうすればいいですか?
 TableView.separatorStyle = UITableViewCellSeparatorStyleNone;  //       ,      
#define SINGLE_LINE_HEIGHT  (1/[UIScreen mainScreen].scale)  //     
#define  COLOR_LINE_GRAY [UIColor colorWithRed:224/255.0f green:224/255.0f blue:224/255.0f alpha:1]  //      #e0e0e0
    cell   :
- (void)drawRect:(CGRect)rect
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSetFillColorWithColor(context, [UIColor clearColor].CGColor);
    CGContextFillRect(context, rect);
    //    
    CGContextSetStrokeColorWithColor(context, COLOR_LINE_GRAY.CGColor); //  COLOR_LINE_GRAY      
    CGContextStrokeRect(context, CGRectMake(0, rect.size.height, rect.size.width, SINGLE_LINE_HEIGHT)); //SINGLE_LINE_HEIGHT      
}
毎日更新のご注意:http://weibo.com/hanjunqiang 
iOS開発者交流QQ群:446310206  問題や技術交流があれば、お問い合わせください.ようこそ!