You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

244 lines
7.1 KiB

//
// addressCell.m
// b
//
// Created by kaidan on 2017/1/12.
// Copyright © 2017年 kaidan. All rights reserved.
//
#import "HomeCellInfo.h"
#import "Masonry.h"
#import "myHelper.h"
@interface HomeCellInfo ()
{
NSString *imgwit;
CLLocation *curLocation;
}
@end
@implementation HomeCellInfo
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
[self addSubViews];
}
return self;
}
-(UIView *)backview{
if (!_backview) {
_backview = [[UIView alloc] init];
}
return _backview;
}
-(UIImageView *)iconImg{
if (!_iconImg) {
_iconImg = [[UIImageView alloc] init];
_iconImg.contentMode = UIViewContentModeScaleAspectFit;
}
return _iconImg;
}
-(UILabel *)titleLab{
if (!_titleLab) {
_titleLab = [[UILabel alloc] init];
}
return _titleLab;
}
-(UILabel *)datelab{
if (!_datelab) {
_datelab = [[UILabel alloc] init];
}
return _datelab;
}
-(UILabel *)datelabB{
if (!_datelabB) {
_datelabB = [[UILabel alloc] init];
}
return _datelabB;
}
//timelab
-(UILabel *)timelab{
if (!_timelab) {
_timelab = [[UILabel alloc] init];
}
return _timelab;
}
-(void)addSubViews{
UILabel* xian = [[UILabel alloc]init];
self.backview.layer.cornerRadius = 8;
CALayer * layer = [self.backview layer];
layer.borderColor = [RGB(240, 240, 242) CGColor];
layer.borderWidth = 0.5f;
//添加四个边阴影
self.backview.layer.shadowColor = [UIColor darkGrayColor].CGColor;//阴影颜色
self.backview.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
self.backview.layer.shadowOpacity = 0.5;//不透明度
// self.backview.layer.shadowRadius = 10.0;//半径
self.titleLab.textColor = mainColor;
self.datelab.textColor = [UIColor lightGrayColor];
self.timelab.textColor = [UIColor lightGrayColor];
self.titleLab.textAlignment = NSTextAlignmentLeft;
self.datelab.textAlignment = NSTextAlignmentLeft;
self.timelab.textAlignment = NSTextAlignmentRight;
self.datelabB.textAlignment = NSTextAlignmentRight;
self.datelab.backgroundColor = [UIColor whiteColor];
self.datelabB.backgroundColor = [UIColor whiteColor];
self.titleLab.backgroundColor = [UIColor whiteColor];
self.backview.backgroundColor = [UIColor whiteColor];
xian.backgroundColor = [UIColor grayColor];
self.iconImg.backgroundColor = [UIColor whiteColor];
self.timelab.backgroundColor = [UIColor whiteColor];
[self.contentView addSubview:self.backview];
self.backgroundColor = [UIColor clearColor];
[self.backview addSubview:xian];
[self.backview addSubview:self.timelab];
[self.backview addSubview:self.iconImg];
[self.backview addSubview:self.titleLab];
[self.backview addSubview:self.datelab];
[self.backview addSubview:self.datelabB];
// [titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
[self.backview mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
/* 等价于
make.top.equalTo(sv).with.offset(10);
make.left.equalTo(sv).with.offset(10);
make.bottom.equalTo(sv).with.offset(-10);
make.right.equalTo(sv).with.offset(-10);
*/
/* 也等价于
make.top.left.bottom.and.right.equalTo(sv).with.insets(UIEdgeInsetsMake(10, 10, 10, 10));
*/
}];
[xian mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backview).with.offset(44);
make.height.mas_equalTo(1);
make.left.equalTo(self.backview).with.offset(0);
make.right.equalTo(self.backview).with.offset(0);
}];
[self.iconImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.width.mas_equalTo(28);
make.left.equalTo(self.backview).with.offset(10);
make.top.equalTo(self.backview).with.offset(8);
}];
[self.titleLab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backview).with.offset(8);
make.height.mas_equalTo(28);
make.width.mas_equalTo(100);
make.left.mas_equalTo(self.iconImg.mas_right).offset(14);
}];
[self.timelab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backview).with.offset(8);
make.height.mas_equalTo(28);
make.width.mas_equalTo(100);
make.right.equalTo(self.backview).with.offset(-14);
}];
[self.datelab mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.equalTo(self.backview).with.offset(46);
make.height.mas_equalTo(38);
make.left.equalTo(self.backview).with.offset(10);
make.right.equalTo(self.backview).with.offset(-10);
}];
[self.datelabB mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(self.datelab.mas_bottom);
make.bottom.equalTo(self.backview).with.offset(-1);
make.left.equalTo(self.backview).with.offset(40);
make.right.equalTo(self.backview).with.offset(-10);
}];
// self.titleLab.font = [UIFont systemFontOfSize:16];
self.datelab.font = [UIFont systemFontOfSize:15];
self.datelab.numberOfLines = 0;
self.datelabB.font = [UIFont systemFontOfSize:13];
xian.backgroundColor = RGB(240, 240, 242);
self.timelab.font = [UIFont systemFontOfSize:13];
}
- (void)setLocation:(CLLocation *)location{
if (location.coordinate.longitude != curLocation.coordinate.longitude &&
location.coordinate.latitude != curLocation.coordinate.latitude) {
curLocation = location;
//反地理编码
CLGeocoder *geocoder = [[CLGeocoder alloc]init];
WEAKSELF
[geocoder reverseGeocodeLocation:location completionHandler:^(NSArray *placemarks, NSError *error) {
CLPlacemark *placemark = [placemarks firstObject];
xLog(@"详细信息:%@",placemark.addressDictionary);
NSString *state = placemark.locality;
if (!state) {
//四大直辖市的城市信息无法通过locality获得,只能通过获取省份的方法来获得(如果city为空,则可知为直辖市)
state = placemark.administrativeArea;
}
weakSelf.datelab.text = [NSString stringWithFormat:@"%@ %@ %@",state,placemark.subLocality,placemark.name];
}];
}
}
-(void)setType:(HomeCellInfoType)type{
_type = type;
switch (type) {
case HomeCellInfoTypeDingWei:
self.datelabB.hidden = NO;
self.iconImg.image =[UIImage imageNamed:@"首页定位"];
self.titleLab.text = @"定位";
break;
case HomeCellInfoTypeJiBu:
self.datelabB.hidden = YES;
self.iconImg.image = [UIImage imageNamed:@"首页计步"];
self.titleLab.text = @"计步";
break;
}
}
@end