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
//
// 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.userLabel.text = @"用户: 陈宁";
self.numberLabel.text = @"代码: 0005";
self.companyLabel.text = @"公司: 红星美凯龙家居集团股份有限公司";
}
#pragma mark - lazy loading
- (UILabel *)companyLabel
{
if (!_companyLabel) {
_companyLabel = [[UILabel alloc] init];
}
_companyLabel.translatesAutoresizingMaskIntoConstraints = NO;
_companyLabel.minimumScaleFactor = .5f;
_companyLabel.adjustsFontSizeToFitWidth = YES;
_companyLabel.textColor = [UIColor whiteColor];
[self addSubview:_companyLabel];
NSLayoutConstraint *companyHeight = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeNotAnAttribute multiplier:1.0 constant:45];
[self addConstraint:companyHeight];
NSLayoutConstraint *companyTop = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeTop multiplier:1.0 constant:40];
[self addConstraint:companyTop];
NSLayoutConstraint *companyRight = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:-20];
[self addConstraint:companyRight];
NSLayoutConstraint *companyLeft = [NSLayoutConstraint constraintWithItem:_companyLabel attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeLeft multiplier:1.0 constant:20];
[self addConstraint:companyLeft];
return _companyLabel;
}
- (UILabel *)userLabel
{
if (!_userLabel) {
_userLabel = [[UILabel alloc] init];
}
_userLabel.textAlignment = NSTextAlignmentCenter;
_userLabel.translatesAutoresizingMaskIntoConstraints = NO;
_userLabel.textColor = [UIColor whiteColor];
[self 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 attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self addConstraint:userLeft];
NSLayoutConstraint *userRight = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self.numberLabel attribute:NSLayoutAttributeLeft multiplier:1.0 constant:0];
[self addConstraint:userRight];
NSLayoutConstraint *userBottom = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self addConstraint:userBottom];
NSLayoutConstraint *userWidth = [NSLayoutConstraint constraintWithItem:_userLabel attribute:NSLayoutAttributeWidth relatedBy:NSLayoutRelationEqual toItem:self.numberLabel attribute:NSLayoutAttributeWidth multiplier:1.0 constant:0];
[self addConstraint:userWidth];
return _userLabel;
}
- (UILabel *)numberLabel
{
if (!_numberLabel) {
_numberLabel = [[UILabel alloc] init];
}
_numberLabel.textAlignment = NSTextAlignmentCenter;
_numberLabel.translatesAutoresizingMaskIntoConstraints = NO;
_numberLabel.textColor = [UIColor whiteColor];
[self 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 addConstraint:numberLeft];
NSLayoutConstraint *numberRight = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeRight multiplier:1.0 constant:0];
[self addConstraint:numberRight];
NSLayoutConstraint *numberBottom = [NSLayoutConstraint constraintWithItem:_numberLabel attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0];
[self 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