-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathWikiHeaderView.m
81 lines (72 loc) · 2.95 KB
/
WikiHeaderView.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
//
// WikiHeaderView.m
// Coding_Enterprise_iOS
//
// Created by Easeeeeeeeee on 2017/4/7.
// Copyright © 2017年 Coding. All rights reserved.
//
#import "WikiHeaderView.h"
@interface WikiHeaderView ()
@property (strong, nonatomic) UILabel *titleL, *nameL, *timeL, *versionL;
@end
@implementation WikiHeaderView
- (instancetype)init{
self = [super init];
if (self) {
self.frame = CGRectMake(0, 0, kScreen_Width, 0);
_titleL = [UILabel labelWithFont:[UIFont systemFontOfSize:17 weight:UIFontWeightMedium] textColor:kColorDark2];
_nameL = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:kColorDark7];
_timeL = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:kColorDark7];
_versionL = [UILabel labelWithFont:[UIFont systemFontOfSize:12] textColor:kColorDark7];
[self addSubview:_titleL];
[self addSubview:_nameL];
[self addSubview:_timeL];
[self addSubview:_versionL];
[_titleL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.top.equalTo(self).offset(kPaddingLeftWidth);
make.right.equalTo(self).offset(-kPaddingLeftWidth);
}];
[_nameL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_titleL);
make.top.equalTo(_titleL.mas_bottom).offset(10);
make.height.mas_equalTo(17);
}];
[_timeL mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(_nameL.mas_right).offset(10);
make.right.equalTo(_versionL.mas_left).offset(-10);
make.centerY.equalTo(_nameL);
}];
[_versionL mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(_nameL);
}];
UIView *lineV = [UIView lineViewWithPointYY:0];
[self addSubview:lineV];
[lineV mas_makeConstraints:^(MASConstraintMaker *make) {
make.height.mas_equalTo(kLine_MinHeight);
make.right.left.equalTo(_titleL);
make.bottom.equalTo(self);
}];
}
return self;
}
- (void)setCurWiki:(EAWiki *)curWiki{
_curWiki = curWiki;
self.hidden = (_curWiki == nil);
if (!_curWiki) {
self.height = 0;
}else{
_titleL.text = _curWiki.mdTitle;
_nameL.text = _curWiki.editor.name;
_timeL.text = [NSString stringWithFormat:@"更新于 %@", [_curWiki.updatedAt stringWithFormat:@"MM/dd HH:mm"]];
_versionL.text = [NSString stringWithFormat:@"当前版本 %@", _curWiki.currentVersion];
_nameL.hidden = _timeL.hidden = _versionL.hidden = _isForEdit;
CGFloat height = [_titleL.text getHeightWithFont:_titleL.font constrainedToSize:CGSizeMake(_titleL.width, kCGGlyphMax)];
if (_isForEdit) {
height = 15 + height + 15 + 1;
}else{
height = 15 + height + 10 + 17 + 15 + 1;
}
self.frame = CGRectMake(0, -height, kScreen_Width, height);
}
}
@end