FreeRDP
Loading...
Searching...
No Matches
EditTextTableViewCell.m
1/*
2 Custom table cell with edit text field
3
4 Copyright 2013 Thincast Technologies GmbH, Author: Martin Fleisz
5
6 This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
7 If a copy of the MPL was not distributed with this file, You can obtain one at
8 http://mozilla.org/MPL/2.0/.
9 */
10
11#import "EditTextTableViewCell.h"
12
13@implementation EditTextTableViewCell
14
15@synthesize label = _label, textfield = _textfield, enabled = _enabled;
16
17- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
18{
19 self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
20 if (self)
21 {
22 // Initialization code
23 [self setSelectionStyle:UITableViewCellSelectionStyleNone];
24
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];
33
34 // right editable field
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];
44
45 UIView *content = [self contentView];
46 [content addSubview:_label];
47 [content addSubview:_textfield];
48
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]
57 multiplier:1.0],
58 [[_textfield trailingAnchor] constraintEqualToAnchor:[margins trailingAnchor]],
59 [[_textfield topAnchor] constraintGreaterThanOrEqualToAnchor:[margins topAnchor]],
60 [[_textfield bottomAnchor] constraintLessThanOrEqualToAnchor:[margins bottomAnchor]],
61 [[_textfield centerYAnchor] constraintEqualToAnchor:[margins centerYAnchor]]
62 ]];
63
64 [self setEnabled:YES];
65 }
66 return self;
67}
68
69- (void)dealloc
70{
71 [_label release];
72 [_textfield release];
73 [super dealloc];
74}
75
76- (void)prepareForReuse
77{
78 [super prepareForReuse];
79
80 [_textfield setKeyboardType:UIKeyboardTypeDefault];
81 [self setEnabled:YES];
82}
83
84- (void)setEnabled:(BOOL)enabled
85{
86 _enabled = enabled;
87
88 // if 'disabled' set grayed out color
89 [_label setTextColor:enabled ? [UIColor labelColor] : [UIColor tertiaryLabelColor]];
90 [_textfield
91 setTextColor:enabled ? [UIColor secondaryLabelColor] : [UIColor tertiaryLabelColor]];
92 [_textfield setEnabled:enabled];
93}
94
95@end