登录 立即注册
金钱:

Code4App-iOS开发-iOS 开源代码库-iOS代码实例搜索-iOS特效示例-iOS代码例子下载-Code4App.com

ios 物流时间轴,自动匹配电话号码,可点击拨打

[复制链接]
来自: 你们纯洁哥 分类: iOS精品源码 上传时间: 2018-3-12 10:51:11
Tag:

项目介绍:

本demo使用MJRefresh来做上拉刷新,MJExtension来做模型解析,YYit做富文本点击事件,话不多说上代码

///控制器内数组添加模型

 NSInteger totalCount = array.count;
    
    //清空数组
    [self.logisticArray removeAllObjects];
    
    for (NSInteger i = 0; i < totalCount; i++) {
        
        CZHLogisticFrameModel *frameModel = [[CZHLogisticFrameModel alloc] init];
        
        CZHLogisticModel *model = [CZHLogisticModel czh_parse:array[i]];
        
        model.indexCount = i;
        
        model.totalCount = totalCount;
        
        frameModel.model = model;
        
        [self.logisticArray addObject:frameModel];
        
    }
    
    [self.tableView reloadData];
    
frameModel实现,计算各个空间的frame以及各控件赋值判断
- (void)setModel:(CZHLogisticModel *)model {
    _model = model;
    
    _contentString = model.content;
    _timeString = model.time;
    
    ///判断颜色
    if (model.indexCount == 0) {
        _contentColor = CZHColor(0xff0000);
        _timeColor = CZHColor(0xff0000);
        _leftRoundColor = CZHColor(0xff0000);
    } else {
        _contentColor = CZHColor(0x999999);
        _timeColor = CZHColor(0x999999);
        _leftRoundColor = CZHColor(0xdfdfdf);
    }
    

    _contentAttributedString = [[NSMutableAttributedString alloc] initWithString:_contentString];
    
    _contentAttributedString.yy_font = CZHGlobelNormalFont(14);
    
    _contentAttributedString.yy_color = _contentColor;
    
    _contentAttributedString.yy_lineSpacing = 10;
    
    
    
    ///匹配电话号码
    NSString *string = _contentString;
    NSError *error = nil;
    NSDataDetector * detector = [NSDataDetector dataDetectorWithTypes:NSTextCheckingTypePhoneNumber error:&error];
    
    
    __block NSUInteger count = 0;
    __block NSString *phoneNumber;
    [detector enumerateMatchesInString:string options:0 range:NSMakeRange(0, [string length]) usingBlock:^(NSTextCheckingResult * _Nullable match, NSMatchingFlags flags, BOOL * _Nonnull stop) {

        if (count == 0) *stop = YES;
        
        if ([match resultType] == NSTextCheckingTypePhoneNumber) {
            phoneNumber = [match phoneNumber];
//            NSLog(@"phoneNumber:%@", phoneNumber);
        }
    }];
    
    if (phoneNumber.length > 0) {
        [_contentAttributedString yy_setTextHighlightRange:[_contentString rangeOfString:phoneNumber]
                                                     color:[UIColor blueColor]
                                           backgroundColor:nil
                                                 tapAction:^(UIView *containerView, NSAttributedString *text, NSRange range, CGRect rect){
                                                     
                                                     NSLog(@"----拨打电话--%@", phoneNumber);
                                                     
                                                     NSMutableString *str=[[NSMutableString alloc]initWithFormat:@"tel:%@",phoneNumber];
                                                     
                                                     [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
                                                     
                                                 }];
    }

    ///计算控件frame
    
    CGSize maxSize = CGSizeMake(ScreenWidth - CZH_ScaleWidth(60), MAXFLOAT);
    CGSize contentLabelSize = [YYTextLayout layoutWithContainerSize:maxSize text:_contentAttributedString].textBoundingSize;
    

    CGFloat contentLabelX = MARGIN_LEFT;
    CGFloat contentLabelY = CZH_ScaleWidth(15);
    CGFloat contentLabelW = contentLabelSize.width;
    CGFloat contentLabelH = contentLabelSize.height;
    _contentLabelF = CGRectMake(contentLabelX, contentLabelY, contentLabelW, contentLabelH);
    
    

    CGSize timeLabelSize = [_timeString czh_sizeWithFont:CZHGlobelNormalFont(11) maxW:MAX_WIDTH];
    CGFloat timeLabelX = MARGIN_LEFT;
    CGFloat timeLabelY = CGRectGetMaxY(_contentLabelF) + CZH_ScaleWidth(10);
    CGFloat timeLabelW = timeLabelSize.width;
    CGFloat timeLabelH = timeLabelSize.height;
    _timeLabelF = CGRectMake(timeLabelX, timeLabelY, timeLabelW, timeLabelH);
    
    
    
    CGFloat leftRoundViewX = 0;
    CGFloat leftRoundViewY = 0;
    CGFloat leftRoundViewW = 0;
    CGFloat leftRoundViewH = 0;
    
    if (model.indexCount == 0) {
        
        leftRoundViewY = CZH_ScaleWidth(15);
        leftRoundViewW = CZH_ScaleWidth(15);
        leftRoundViewH = CZH_ScaleWidth(15);
        
    } else {
        leftRoundViewY = CZH_ScaleWidth(19);
        leftRoundViewW = CZH_ScaleWidth(7);
        leftRoundViewH = CZH_ScaleWidth(7);
        
    }
    leftRoundViewX = (MARGIN_LEFT - leftRoundViewW) * 0.5;
    
    _leftRoundViewF = CGRectMake(leftRoundViewX, leftRoundViewY, leftRoundViewW, leftRoundViewH);
    
    
    _cellHeight = CGRectGetMaxY(_timeLabelF) + CZH_ScaleWidth(15);
    
    
    if (model.indexCount == model.totalCount - 1) {
        _bottomLineF = CGRectZero;
    } else {
        CGFloat bottomLineX = MARGIN_LEFT;
        CGFloat bottomLineY = _cellHeight - 0.5;
        CGFloat bottomLineW = ScreenWidth - bottomLineX;
        CGFloat bottomLineH = 0.5;
        _bottomLineF = CGRectMake(bottomLineX, bottomLineY, bottomLineW, bottomLineH);
    }
    
    
    CGFloat leftLineViewW = 1;
    CGFloat leftLineViewX = (MARGIN_LEFT - leftLineViewW) * 0.5;
    CGFloat leftLineViewY = 0;
    CGFloat leftLineViewH = 0;
    
    if (model.indexCount == 0) {//第一个
        leftLineViewY = CGRectGetMaxY(_leftRoundViewF);
        leftLineViewH = _cellHeight - leftLineViewY;
    } else if (model.indexCount == model.totalCount - 1) {//最后一个
        leftLineViewY = 0;
        leftLineViewH = CGRectGetMinY(_leftRoundViewF);
    } else {
        leftLineViewY = 0;
        leftLineViewH = _cellHeight;
    }
    _leftLineViewF = CGRectMake(leftLineViewX, leftLineViewY, leftLineViewW, leftLineViewH);
}
cell赋值
- (void)setFrameModel:(CZHLogisticFrameModel *)frameModel {
    _frameModel = frameModel;
    
    [self czh_setData];
    
}

- (void)czh_setData {
    

    self.timeLabel.text = _frameModel.timeString;
    

    self.contentLabel.textColor = _frameModel.contentColor;
    self.timeLabel.textColor = _frameModel.timeColor;
    self.leftRoundView.backgroundColor = _frameModel.leftRoundColor;
   
    self.contentLabel.attributedText = _frameModel.contentAttributedString;
    
}



- (void)layoutSubviews {
    [super layoutSubviews];
    
    self.leftRoundView.frame = _frameModel.leftRoundViewF;
    [self.leftRoundView czh_cornerAllCornersWithCornerRadius:self.leftRoundView.czh_height * 0.5];
    
    self.leftLineView.frame = _frameModel.leftLineViewF;
    
    self.contentLabel.frame = _frameModel.contentLabelF;
    
    self.timeLabel.frame = _frameModel.timeLabelF;
    
    self.bottomLine.frame = _frameModel.bottomLineF;
}

github地址

相关源码推荐:

我来说两句
*滑动验证:
所有评论(12)
逆鳞九霄 2018-3-12 14:30:12
学习学习!
回复
phoiu 2018-3-12 14:30:31
感谢大神分享,必须顶!
回复
Wsdtg 2018-3-12 14:30:33
小弟学习了~支持,支持
回复
打个酱油的 2018-3-12 14:30:40
感谢大神~
回复
乱世佳人520 2018-3-12 14:30:42
相当不错,感谢无私分享精神!
回复
这是个逗比 2018-3-12 14:30:49
相当不错,感谢无私分享精神!
回复
码农创新者 2018-3-12 14:30:53
不错不错,楼主辛苦了。。。
回复
code4app热心网友 2018-3-12 15:31:24
淡定,淡定,淡定……
回复
codegogo 2018-3-12 15:33:15
强烈支持楼主ing……
回复
12下一页
提取码:  下载次数:76 状态:已购或VIP 售价:0(原价:15)金钱 下载权限:初级码农 
1112 0 76
联系我们
首页/微信公众账号投稿

帖子代码编辑/版权问题

QQ:435399051,742864542

如何获得代码达人称号?

代码贡献英雄榜
用户名 下载数
通过邮件订阅最新 Code4App 信息
上一条 /4 下一条
联系我们
关闭
合作电话:
13802416937
Email:
435399051@qq.com
商务市场合作/投稿
问题反馈及帮助
联系我们

广告投放| Github|申请友链|手机版|Code4App ( 粤ICP备15117877号-1 )

快速回复 返回顶部 返回列表