iOS-常用小技巧-01

2016-06-02  本文已影响38人  Mr_Bob_
一、去掉tableviewcell的左边多余的15像素
/**
 *  重写这个方法的目的: 能够拦截所有设置cell frame的操作
 */
 - (void)setFrame:(CGRect)frame
{
    // 这里可以自定义cell分割线的样式
    CGFloat margin= 1;
    frame.size.height -= margin;
    frame.origin.y += margin;
    
    [super setFrame:frame];
}
 if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [self.tableView setSeparatorInset:UIEdgeInsetsZero];    
}   
 if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {        
        [self.tableView setLayoutMargins:UIEdgeInsetsZero];
}

然后在重写willDisplayCell方法

 - (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];    
    }
}

即可实现分割线的长度 = 屏幕的宽度

二、调节Label的行间距

   NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:self.contentLabel.text];
  NSMutableParagraphStyle *paragraphStyle =  [[NSMutableParagraphStyle alloc] init];
  [paragraphStyle setLineSpacing:3];
    
    //调整行间距
    [attributedString addAttribute:NSParagraphStyleAttributeName  value:paragraphStyle range:NSMakeRange(0, [self.contentLabel.text length])];
    self.contentLabel.attributedText = attributedString;
三、iOS 开发中一些相关的路径
四、获取 iOS 路径的方法
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
五、字符串相关操作
六、NULL – nil – Nil – NSNULL的区别
上一篇 下一篇

猜你喜欢

热点阅读