forked from huobazi/DSBBM
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FriendTableViewCell.m
135 lines (95 loc) · 3.39 KB
/
FriendTableViewCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// FriendTableViewCell.m
// DSBBM
//
// Created by bisheng on 14-11-3.
// Copyright (c) 2014年 qt. All rights reserved.
//
#import "FriendTableViewCell.h"
@interface FriendTableViewCell ()
@property (nonatomic, strong)UIImageView *doomViewOfIcon;
@end
@implementation FriendTableViewCell
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initSubViews];
// Initialization code
}
return self;
}
-(void)initSubViews
{
//用户头像
_Headimg=[[UIImageView alloc]init];
[self.contentView addSubview:_Headimg];
_Headimg.layer.cornerRadius = 20;
_Headimg.layer.masksToBounds = YES;
//用户名
_Namelab=[[UILabel alloc]init];
_Namelab.font = [UIFont systemFontOfSize:15];
_Namelab.textColor=[UIColor blackColor];
_Namelab.textAlignment=NSTextAlignmentCenter;
[self.contentView addSubview:_Namelab];
//年纪的背景
_Age = [[UIImageView alloc]init];
[self.contentView addSubview:_Age];
//年纪
_AgeLabe = [[UILabel alloc]init];
_AgeLabe.font = [UIFont systemFontOfSize:12];
_AgeLabe.textColor = [UIColor whiteColor];
_AgeLabe.textAlignment = NSTextAlignmentCenter;
[self.contentView addSubview:_AgeLabe];
UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 49, 320, 0.5)];
line.backgroundColor = [UIcol hexStringToColor:@"#c8c8c8"];
[self.contentView addSubview:line];
//大 v img
_DVimg=[[UIImageView alloc]init];
[self.contentView addSubview:_DVimg];
}
-(void)layoutSubviews
{
[super layoutSubviews];
CGFloat headX = 10;
CGFloat headY = 5;
CGFloat headW = 40;
CGFloat headH = 40;
//头像的frame
_Headimg.frame=CGRectMake(headX, headY, headW, headH);
/*自定义高度*/
UIFont * tfont = [UIFont systemFontOfSize:15];
_Namelab.font = tfont;
_Namelab.lineBreakMode =NSLineBreakByTruncatingTail ;
//高度估计文本大概要显示几行,宽度根据需求自己定义。 MAXFLOAT 可以算出具体要多高
CGSize size =CGSizeMake(300,60);
// label可设置的最大高度和宽度
// CGSize size = CGSizeMake(300.f, MAXFLOAT);
// 获取当前文本的属性
NSDictionary * tdic = [NSDictionary dictionaryWithObjectsAndKeys:tfont,NSFontAttributeName,nil];
//ios7方法,获取文本需要的size,限制宽度
CGSize actualsize =[_Namelab.text boundingRectWithSize:size options:NSStringDrawingUsesLineFragmentOrigin attributes:tdic context:nil].size;
// 更新UILabel的frame
CGFloat nameX = headY + headW + 15;
CGFloat nameY = 25 - actualsize.height / 2;
CGFloat nameW = actualsize.width;
CGFloat nameH = actualsize.height;
_Namelab.frame =CGRectMake(nameX, nameY, nameW, nameH);
/*
男生/女生
**/
CGFloat ageX = nameX + nameW + 10;
CGFloat ageY = nameY + 5;
CGFloat ageW = 15;
CGFloat ageH = 12;
_Age.frame = CGRectMake(ageX, ageY, ageW, ageH);
_AgeLabe.frame = _Age.frame;
}
- (void)awakeFromNib {
// Initialization code
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end