-
Notifications
You must be signed in to change notification settings - Fork 0
/
TableViewCell1.m
95 lines (73 loc) · 2.57 KB
/
TableViewCell1.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
//
// TableViewCell1.m
// AutolayoutTesting
//
// Created by Agathe Battestini on 3/29/13.
// Copyright (c) 2013. All rights reserved.
//
#import "TableViewCell1.h"
@implementation TableViewCell1
static CGFloat allFontSize = 10.0;
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[self initialize];
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self initialize];
}
return self;
}
- (void)initialize
{
self.translatesAutoresizingMaskIntoConstraints = YES;
self.contentView.translatesAutoresizingMaskIntoConstraints = YES;
self.contentView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.contentView.backgroundColor = [UIColor yellowColor];
UILabel *label = [[UILabel alloc] init];
label.translatesAutoresizingMaskIntoConstraints = NO;
[self.contentView addSubview:label];
[label setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisHorizontal];
[label setContentHuggingPriority:UILayoutPriorityDefaultLow forAxis:UILayoutConstraintAxisVertical];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-0-[label]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
// [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[label]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(label)]];
label.backgroundColor = [UIColor whiteColor];
label.text = @"hello";
label.font = [UIFont systemFontOfSize:allFontSize];
self.label = label;
}
//- (void)updateConstraints
//{
// [super updateConstraints];
// NSLog(@"here");
//}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
+(CGFloat)fontSize
{
return allFontSize;
}
+ (void)setFontSize:(CGFloat)fontSize
{
allFontSize = fontSize;
}
+ (CGFloat)heightForCell
{
return allFontSize *2.0;
}
- (void)prepareForReuse
{
[super prepareForReuse];
self.label.font = [UIFont systemFontOfSize:allFontSize];
}
@end