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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
//
// MineTableHeaderView.m
// redstar
//
// Created by admin on 15/10/24.
// Copyright © 2015年 ZWF. All rights reserved.
//
#import "MineTableHeaderView.h"
@interface MineTableHeaderView()
@end
@implementation MineTableHeaderView
#pragma mark - init
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor grayColor];
[self setup];
}
return self;
}
#pragma mark - Private Methods
- (void)setup
{
self.bgImageView.image = [UIImage imageNamed:@"SystemImage"];
self.userLabel.text = [NSString stringWithFormat:@"用户: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"user_name"]];
self.numberLabel.text = [NSString stringWithFormat:@"代码: %@", [[NSUserDefaults standardUserDefaults] objectForKey:@"user_code"]];
self.companyLabel.text = @"公司: 红星美凯龙";
}
#pragma mark - lazy loading
- (UIImageView *)bgImageView
{
if (!_bgImageView) {
_bgImageView = [[UIImageView alloc] init];
_bgImageView.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:_bgImageView];
NSLayoutConstraint *companyHeight = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:150];
[self addConstraint:companyHeight];
NSLayoutConstraint *companyTop = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:0];
[self addConstraint:companyTop];
NSLayoutConstraint *companyRight = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self addConstraint:companyRight];
NSLayoutConstraint *companyLeft = [NSLayoutConstraint constraintWithItem:_bgImageView attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self addConstraint:companyLeft];
}
return _bgImageView;
}
- (UILabel *)companyLabel
{
if (!_companyLabel) {
_companyLabel = [[UILabel alloc] init];
}
_companyLabel.textAlignment = NSTextAlignmentCenter;
_companyLabel.translatesAutoresizingMaskIntoConstraints = NO;
_companyLabel.minimumScaleFactor = .5f;
_companyLabel.adjustsFontSizeToFitWidth = YES;
_companyLabel.textColor = [UIColor whiteColor];
[self.bgImageView addSubview:_companyLabel];
NSLayoutConstraint *companyHeight = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
[self.bgImageView addConstraint:companyHeight];
NSLayoutConstraint *companyTop = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeTop multiplier:1.0 constant:40];
[self.bgImageView addConstraint:companyTop];
NSLayoutConstraint *companyRight = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self.bgImageView addConstraint:companyRight];
NSLayoutConstraint *companyLeft = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self.bgImageView addConstraint:companyLeft];
return _companyLabel;
}
- (UILabel *)userLabel
{
if (!_userLabel) {
_userLabel = [[UILabel alloc] init];
}
_userLabel.textAlignment = NSTextAlignmentCenter;
_userLabel.translatesAutoresizingMaskIntoConstraints = NO;
_userLabel.textColor = [UIColor whiteColor];
[self.bgImageView addSubview:_userLabel];
NSLayoutConstraint *userHeight = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35];
[_userLabel addConstraint:userHeight];
NSLayoutConstraint *userLeft = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.bgImageView addConstraint:userLeft];
NSLayoutConstraint *userRight = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.numberLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self.bgImageView addConstraint:userRight];
NSLayoutConstraint *userBottom = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.bgImageView addConstraint:userBottom];
NSLayoutConstraint *userWidth = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.numberLabel attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
[self.bgImageView addConstraint:userWidth];
return _userLabel;
}
- (UILabel *)numberLabel
{
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
}
_numberLabel.textAlignment = NSTextAlignmentCenter;
_numberLabel.translatesAutoresizingMaskIntoConstraints = NO;
_numberLabel.textColor = [UIColor whiteColor];
[self.bgImageView addSubview:_numberLabel];
NSLayoutConstraint *numberHeight = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:35];
[_numberLabel addConstraint:numberHeight];
NSLayoutConstraint *numberLeft = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:_userLabel attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.bgImageView addConstraint:numberLeft];
NSLayoutConstraint *numberRight = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self.bgImageView addConstraint:numberRight];
NSLayoutConstraint *numberBottom = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bgImageView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self.bgImageView addConstraint:numberBottom];
return _numberLabel;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
@end