自动布局Cell

//

//  ProfileCell.m

//  JuXin

//

//  Created by huang on 15/2/6.

//  Copyright (c) 2015 huang. All rights reserved.

//


#import "ProfileCell.h"

#define SIZE_SCALE ([UIScreen mainScreen].bounds.size.width / 320.0)

@implementation ProfileCell

{

    UIView *_lineView;

    UIView *_backView;

    UILabel *_relationshipLB;

}

- (void)awakeFromNib

{

    NSLog(@"神奇的现象");

}


-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];

    if (self) {

        _headImageview = [[UIImageView alloc] init];

        _headImageview.frame = CGRectMake(8, 11, 45, 45);

        _headImageview.layer.cornerRadius = 3;

        _headImageview.clipsToBounds = YES;

        _headImageview.contentMode = UIViewContentModeScaleAspectFill;


        [self.contentView addSubview:_headImageview];

        

        _nameLabel = [[UILabel alloc] init];

        _nameLabel.textColor = [UIColor blackColor];

        _nameLabel.font = [UIFont systemFontOfSize:16.0f];

        [self.contentView addSubview:_nameLabel];

        

        _comLabel = [[UILabel alloc] init];

        _comLabel.textColor = RGB(128, 128, 128);

        _comLabel.font = [UIFont systemFontOfSize:12.0f];

        [self.contentView addSubview:_comLabel];

        

        _jobLabel = [[UILabel alloc] init];

        _jobLabel.textColor = RGB(128, 128, 128);

        _jobLabel.font = [UIFont systemFontOfSize:12.0f];

        [self.contentView addSubview:_jobLabel];

        

        

        self.tagLabel = [[UILabel alloc] init];

        _tagLabel.textColor = RGB(239, 118, 20);

        _tagLabel.font = [UIFont systemFontOfSize:14];

        _tagLabel.layer.cornerRadius = 2;

        _tagLabel.text = @"标签";

        _tagLabel.textAlignment = NSTextAlignmentCenter;

        _tagLabel.layer.borderWidth = 1;

        _tagLabel.layer.borderColor = RGB(252, 226, 212).CGColor;

        [self.contentView addSubview:self.tagLabel];

        

        

        

        _backView = [[UIView alloc]init];

        _backView.layer.borderColor = [UIColor colorWithRed:252.0/255.0 green:226.0/255.0 blue:212.0/255.0 alpha:1.0].CGColor;

        [_backView.layer setMasksToBounds:YES];

        [_backView.layer setCornerRadius:3.0]; //设置矩圆角半径

        [_backView.layer setBorderWidth:1.0];   //边框宽度

        [self.contentView addSubview:_backView];

        

        _subTitleLabel = [[UILabel alloc] init];

        _subTitleLabel.font = [UIFont systemFontOfSize:14.0f];

        _subTitleLabel.textColor = [UIColor colorWithRed:240.0/255.0 green:118.0/255.0 blue:27.0/255.0 alpha:1.0];

        [self.contentView addSubview:_subTitleLabel];

        

        _relationshipLB = [[UILabel alloc] init];

        _relationshipLB.font = [UIFont systemFontOfSize:12.0f];;

        _relationshipLB.textColor = RGB(128, 128, 128);;

        [self.contentView addSubview:_relationshipLB];

        

        

        _lineView = [[UIView alloc]init];

        _lineView.backgroundColor = RGB(217, 217, 217);

        _lineView.frame = CGRectMake(0, 128/2.0*SIZE_SCALE - 1, 320*SIZE_SCALE, 1);

        _lineView.hidden = YES;

        [self addSubview:_lineView];

        

    }

    return self;

}


-(void)lineViewHidden:(BOOL)hidden

{

    _lineView.hidden = hidden;

}


-(void)setAllFrame:(NSDictionary *)tmpDic

{

    self.selectionStyle = UITableViewCellSelectionStyleNone;

    self.headImageview.frame = CGRectMake(8, 11, 45, 45);

    

    

    NSString *imageURL = [tmpDic objectForKey:@"photo"];

    

     UIImage *image = [ImageTool createImageWithName:[tmpDic objectForKey:@"nickname"] andUserId:[NSNumber numberWithInteger:[[tmpDic objectForKey:@"userid"] integerValue]] andSize:self.headImageview.frame.size];

       [self.headImageview sd_setImageWithURL:[NSURL URLWithString:imageURL] placeholderImage:image ];

    

    

    int totalWidth = KDeviceW - 70 - 5;

    CGSize nameSize = [[tmpDic objectForKey:@"nickname"] sizeWithFont:[UIFont systemFontOfSize:16.0] constrainedToSize:CGSizeMake(KDeviceW, 21) lineBreakMode:NSLineBreakByCharWrapping];

    if(nameSize.width > totalWidth/3)

    {

        self.nameLabel.frame = CGRectMake(61, 14, totalWidth/3, 21);

    }

    else

    {

        self.nameLabel.frame = CGRectMake(61, 14, nameSize.width, 21);

    }

    //self.tagLabel.frame = CGRectMake(61, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height +1, 40, 20);

    //self.subTitleLabel.frame = CGRectMake(61+40+10, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height +3, KDeviceW -70-5 -40-10 , 20);

    self.tagLabel.hidden=YES;

    

    self.nameLabel.text = [tmpDic objectForKey:@"nickname"];

    

    //替换

      NSDictionary *attribute = @{NSFontAttributeName: [UIFont systemFontOfSize:12.0]};

            CGSize  compSize = [[NSString stringWithFormat:@"  | %@",[tmpDic objectForKey:@"company"]] boundingRectWithSize:CGSizeMake(KDeviceW, 18) options:NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;

    

   

             CGSize jobSize = [[NSString stringWithFormat:@"%@",[tmpDic objectForKey:@"jobposition"]] boundingRectWithSize:CGSizeMake(KDeviceW, 18) options: NSStringDrawingUsesLineFragmentOrigin attributes:attribute context:nil].size;

    

//    CGSize  compSize = [[NSString stringWithFormat:@"  | %@",[tmpDic objectForKey:@"company"]] sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake(KDeviceW, 18) lineBreakMode:NSLineBreakByCharWrapping];

//    

//    CGSize jobSize = [[NSString stringWithFormat:@"%@",[tmpDic objectForKey:@"jobposition"]] sizeWithFont:[UIFont systemFontOfSize:12.0] constrainedToSize:CGSizeMake(KDeviceW, 18) lineBreakMode:NSLineBreakByCharWrapping];

    

    if(compSize.width +jobSize.width >self.frame.size.width - self.nameLabel.frame.size.width -self.nameLabel.frame.origin.x -20)

    {

        if (compSize.width <totalWidth/3) {

            self.comLabel.frame = CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width, 14.5, compSize.width, 18);

            self.jobLabel.frameCGRectMake(self.comLabel.frame.origin.x + self.comLabel.frame.size.width, 14.5, self.frame.size.width - self.comLabel.frame.origin.x - self.comLabel.frame.size.width -20, 18);

        }else if(jobSize.width <totalWidth/3)

        {

            self.comLabel.frame = CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width, 14.5, self.frame.size.width -(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width) - jobSize.width-20, 18);

            self.jobLabel.frameCGRectMake(self.comLabel.frame.origin.x + self.comLabel.frame.size.width, 14.5, jobSize.width, 18);

        }else

        {

            CGFloat width = self.frame.size.width - self.nameLabel.frame.size.width -self.nameLabel.frame.origin.x -20;

            self.comLabel.frame = CGRectMake(self.nameLabel.frame.origin.x+self.nameLabel.frame.size.width, 14.5,width/2, 18);

            self.jobLabel.frame = CGRectMake(self.comLabel.frame.origin.x + self.comLabel.frame.size.width, 14.5, width/2, 18);

        }

    }else

    {

        self.comLabel.frame = CGRectMake(self.nameLabel.frame.origin.x+self.nameLabel.frame.size.width, 14.5,compSize.width , 18);

        self.jobLabel.frame = CGRectMake(self.comLabel.frame.origin.x + self.comLabel.frame.size.width, 14.5, jobSize.width, 18);

    }

    

    

    self.comLabel.text = [NSString stringWithFormat:@"  | %@",[tmpDic objectForKey:@"company"]];

    self.jobLabel.text = [NSString stringWithFormat:@"%@",[tmpDic objectForKey:@"jobposition"]];

   

    if([[tmpDic objectForKey:@"relationship"] isEqualToString:@"(null)"])

    {

        NSLog(@"labers  %@",[tmpDic objectForKey:@"relationship"]);

        self.subTitleLabel.text = @"暂无";

    }

    else

    {

        self.subTitleLabel.text = [tmpDic objectForKey:@"relationtag"];

    }

    _relationshipLB.text = [tmpDic objectForKey:@"relationvalue"];

    

    self.subTitleLabel.frame = CGRectMake(64, self.nameLabel.frame.origin.y + self.nameLabel.frame.size.height +4, KDeviceW -70-5-10, 17);

    [_subTitleLabel sizeToFit];

    _backView.frame = CGRectMake(60, self.subTitleLabel.frame.origin.y - 1, self.subTitleLabel.frame.size.width + 8, 19);

    _relationshipLB.frame = CGRectMake(_backView.frame.origin.x + _backView.frame.size.width + 5, self.subTitleLabel.frame.origin.y, KDeviceW - (_backView.frame.origin.x + _backView.frame.size.width + 5), 17);

}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated

{

    [super setSelected:selected animated:animated];

}


@end

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值