// // FenceSiteCell.m // jiaPei // // Created by apple on 2017/8/16. // Copyright © 2017年 JCZ. All rights reserved. // #import "FenceSiteCell.h" #import "descVC.h" #import "MapVC.h" @implementation FenceSiteCell - (void)awakeFromNib { [super awakeFromNib]; } -(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { CGFloat x,y,w,h; x = y = 10; w = 150; if (kSize.width == 320) { w = 130; } h = 120; headImg = [[UIImageView alloc] setxywh]; headImg.layer.masksToBounds = YES; headImg.layer.cornerRadius = 5; headImg.clipsToBounds = YES; [headImg setContentMode:UIViewContentModeScaleAspectFit]; [self.contentView addSubview:headImg]; headImg.userInteractionEnabled = YES; [headImg addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapImage:)]]; x += w + 10; w = kSize.width - x - 10; h = 24; UILabel *label = [[UILabel alloc] setxywh]; [label setText:@"" Font:FontLarger TextColor:defGreen]; [self.contentView addSubview:label]; nameLabel = label; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; timeLabel = label; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; carTypeLabel = label; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; carModelLabel = label; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; areaLabel = label; //简介 x = 10; y += h + 15; w = kSize.width - 20; h = 29; label = [[UILabel alloc] setxywh]; [label setText:@"场地简介" Font:FontTitle TextColor:kTitleColor Alignment:NSTextAlignmentLeft]; [self.contentView addSubview:label]; label = [[UILabel alloc] setxywh]; [label setText:@"更多 >" Font:Font17 TextColor:defGreen Alignment:NSTextAlignmentRight]; [self.contentView addSubview:label]; UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, y, kSize.width, h)]; [btn target:self tag:1]; [self.contentView addSubview:btn]; lookMoreBtn = btn; [self.contentView addViewWithRect:CGRectMake(0, y - 7, kSize.width, 7)]; [self.contentView addViewWithRect:CGRectMake(0, y + h, kSize.width, 1)]; y += h + 5; h = 60; label = [[UILabel alloc] setxywh]; [label setText:@"暂无简介" Font:NormalFont TextColor:kTitleColor]; label.numberOfLines = 0; [self.contentView addSubview:label]; remarkLabel = label; //地址 y += h + 10; h = 30; w -= 85; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; adressLabel = label; btn = [[UIButton alloc] initWithFrame:CGRectMake(x + w + 5, y, 80, h)]; [btn setTitle:@"查看地图" textColor:defGreen font:Font17 fotState:UIControlStateNormal]; [btn target:self tag:2]; [self.contentView addSubview:btn]; lookMapBtn = btn; y += h; w = kSize.width - 2*x; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; lineLabel = label; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; principalLabel = label; x += 120; w = kSize.width - x;; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; mobileLabel = label; btn = [[UIButton alloc] setxywh]; [btn target:self tag:3]; [self.contentView addSubview:btn]; mobileBtn = btn; y += h; label = [[UILabel alloc] setxywh]; [label setText:@"" Font:Font17 TextColor:kTitleColor]; [self.contentView addSubview:label]; telLabel = label; btn = [[UIButton alloc] setxywh]; [btn target:self tag:4]; [self.contentView addSubview:btn]; telBtn = btn; } return self; } -(void)setDataDic:(NSDictionary *)dataDic { _dataDic = dataDic; NSArray *imgs = dataDic[@"imgs"]; if (imgs.count > 0) { NSString *img = [[imgs firstObject] objectForKey:@"IMGPATH"]; [headImg sd_setImageWithURL:[NSURL URLWithString:img] placeholderImage:[UIImage imageNamed:@"暂无图片"]]; }else{ headImg.image = [UIImage imageNamed:@"暂无图片"]; } nameLabel.text = dataDic[@"NAME"]; timeLabel.text = [NSString stringWithFormat:@"训练时间:%@",dataDic[@"TRAINTIME"]]; carTypeLabel.text = [NSString stringWithFormat:@"带教车型:%@",dataDic[@"TRAINTYPE"]]; carModelLabel.text = [NSString stringWithFormat:@"训练车品牌:%@",dataDic[@"CARMODEL"]]; areaLabel.text = [NSString stringWithFormat:@"场地占地面积:%@m2",dataDic[@"AREA"]]; NSString *remarkString = @"暂无简介"; if ([dataDic[@"REMARK"] length] > 0) { remarkString = dataDic[@"REMARK"]; } remarkLabel.text = remarkString; adressLabel.text = [NSString stringWithFormat:@"地址:%@",dataDic[@"ADDRESS"]]; lineLabel.text = [NSString stringWithFormat:@"接送点:%@",[dataDic[@"ISPICKUP"] intValue] == 0?@"不接送":dataDic[@"PICK_LINE"]]; principalLabel.text = [NSString stringWithFormat:@"联系人:%@",dataDic[@"PRINCIPAL"]]; [self setLabelTextWithLabel:mobileLabel textString:[NSString stringWithFormat:@"联系电话:%@",dataDic[@"MOBILE"]]]; [self setLabelTextWithLabel:telLabel textString:[NSString stringWithFormat:@"固定电话:%@",dataDic[@"TELPHONE"]]]; } - (void)btnClick:(UIButton *)sender { // NSLog(@"click-----><>%d",(int)sender.tag); if (sender.tag == 1) { descVC *vc = [[descVC alloc] init]; vc.desc = _dataDic[@"REMARK"]; vc.titleString = @"场地简介"; [_superVC navPushHideTabbarToVC:vc]; } if (sender.tag == 2) { MapVC *map = [[MapVC alloc] init]; map.isJustLoad = YES; map.lat = [_dataDic[@"BDLAT"] floatValue]; map.lng = [_dataDic[@"BDLNG"] floatValue]; map.siteName = _dataDic[@"NAME"]; [_superVC navPushHideTabbarToVC:map]; } if (sender.tag == 3) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:_dataDic[@"MOBILE"] message:nil preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",_dataDic[@"MOBILE"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; }]]; [_superVC presentViewController:alert animated:YES completion:nil]; } if (sender.tag == 4) { UIAlertController *alert = [UIAlertController alertControllerWithTitle:_dataDic[@"TELPHONE"] message:nil preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alert addAction:[UIAlertAction actionWithTitle:@"呼叫" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) { NSMutableString * url=[[NSMutableString alloc] initWithFormat:@"tel:%@",_dataDic[@"TELPHONE"]]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]]; }]]; [_superVC presentViewController:alert animated:YES completion:nil]; } } //用富文本封装个方法供调用 -(void)setLabelTextWithLabel:(UILabel *)label textString:(NSString *)str { NSMutableAttributedString *abs = [[NSMutableAttributedString alloc]initWithString:str]; [abs beginEditing]; //字体大小 // [abs addAttribute:NSFontAttributeName // value:[UIFont scaleSize:30.0] // range:NSMakeRange(8, 1)]; //字体颜色 [abs addAttribute:NSForegroundColorAttributeName value:defGreen range:NSMakeRange(5, str.length - 5)]; //下划线 [abs addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(5, str.length - 5)]; label.attributedText = abs; } -(void)tapImage:(UITapGestureRecognizer *)tap { NSArray *dataSource = _dataDic[@"imgs"]; if (dataSource.count < 1) { return; } [RQ_SHARE_FUNCTION showPhotoBrowserWithDataSource:dataSource currentIndex:0 isCanSave:YES]; } - (void)setSelected:(BOOL)selected animated:(BOOL)animated { [super setSelected:selected animated:animated]; } @end