11#import "EditTextTableViewCell.h"
15@synthesize label = _label, textfield = _textfield, enabled = _enabled;
17- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
19 self = [
super initWithStyle:style reuseIdentifier:reuseIdentifier];
23 [
self setSelectionStyle:UITableViewCellSelectionStyleNone];
25 _label = [[UILabel alloc] init];
26 [_label setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
27 [_label setAdjustsFontForContentSizeCategory:YES];
28 [_label setTranslatesAutoresizingMaskIntoConstraints:NO];
29 [_label setContentHuggingPriority:UILayoutPriorityRequired
30 forAxis:UILayoutConstraintAxisHorizontal];
31 [_label setContentCompressionResistancePriority:UILayoutPriorityRequired
32 forAxis:UILayoutConstraintAxisHorizontal];
35 _textfield = [[UITextField alloc] init];
36 [_textfield setFont:[UIFont preferredFontForTextStyle:UIFontTextStyleBody]];
37 [_textfield setAdjustsFontForContentSizeCategory:YES];
38 [_textfield setTextAlignment:NSTextAlignmentRight];
39 [_textfield setClearButtonMode:UITextFieldViewModeWhileEditing];
40 [_textfield setAutocorrectionType:UITextAutocorrectionTypeNo];
41 [_textfield setAutocapitalizationType:UITextAutocapitalizationTypeNone];
42 [_textfield setSpellCheckingType:UITextSpellCheckingTypeNo];
43 [_textfield setTranslatesAutoresizingMaskIntoConstraints:NO];
45 UIView *content = [
self contentView];
46 [content addSubview:_label];
47 [content addSubview:_textfield];
49 UILayoutGuide *margins = [content layoutMarginsGuide];
50 [NSLayoutConstraint activateConstraints:@[
51 [[_label leadingAnchor] constraintEqualToAnchor:[margins leadingAnchor]],
52 [[_label topAnchor] constraintGreaterThanOrEqualToAnchor:[margins topAnchor]],
53 [[_label bottomAnchor] constraintLessThanOrEqualToAnchor:[margins bottomAnchor]],
54 [[_label centerYAnchor] constraintEqualToAnchor:[margins centerYAnchor]],
55 [[_textfield leadingAnchor]
56 constraintEqualToSystemSpacingAfterAnchor:[_label trailingAnchor]
58 [[_textfield trailingAnchor] constraintEqualToAnchor:[margins trailingAnchor]],
59 [[_textfield topAnchor] constraintGreaterThanOrEqualToAnchor:[margins topAnchor]],
60 [[_textfield bottomAnchor] constraintLessThanOrEqualToAnchor:[margins bottomAnchor]],
61 [[_textfield centerYAnchor] constraintEqualToAnchor:[margins centerYAnchor]]
64 [
self setEnabled:YES];
76- (void)prepareForReuse
78 [
super prepareForReuse];
80 [_textfield setKeyboardType:UIKeyboardTypeDefault];
81 [
self setEnabled:YES];
84- (void)setEnabled:(BOOL)enabled
89 [_label setTextColor:enabled ? [UIColor labelColor] : [UIColor tertiaryLabelColor]];
91 setTextColor:enabled ? [UIColor secondaryLabelColor] : [UIColor tertiaryLabelColor]];
92 [_textfield setEnabled:enabled];