featherless bbe4a23fe0
Remove all __IPHONE_11_0 checks now that we no longer support Xcode 8. (#4915)
We can now make use of @available throughout our codebase.

We support Xcode 9 and up, which includes the iOS 11 SDK. This means we can remove any guards for SDKs prior to iOS 11.

This was cleaned up by running a global find-and-replace with the following regular expression:

```
Find:#if defined\(__IPHONE_11_0\) && \(__IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_11_0\)\n(.+if \(@available\(iOS 11.0, \*\)\) \{(?:.|\n)*?)(?:#else(?:.|\n)*?)?\n#endif
Replace:$1
```

With some additional cleanup for stragglers that didn't match this pattern. Note that else clauses were intentionally dropped.

Closes https://github.com/material-components/material-components-ios/issues/4909
2018-08-28 09:57:30 -04:00

150 lines
4.9 KiB
Objective-C

/*
Copyright 2018-present the Material Components for iOS authors. All Rights Reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
#import "MaterialTextFields.h"
static NSString *const TSTTextFieldTableViewCellIdentifier = @"TSTTextFieldsTableViewExampleCell";
@interface TextFieldTableViewCell : UITableViewCell
@property(nonatomic, strong) MDCTextField *textField;
@property(nonatomic, strong) MDCTextInputControllerFilled *textFieldController;
@end
@interface TextFieldsTableViewExample : UIViewController <UITableViewDataSource, UITextFieldDelegate>
@property(nonatomic, strong) NSMutableArray <NSString *> *strings;
@property(nonatomic, strong) UITableView *tableView;
@end
@implementation TextFieldsTableViewExample
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:CGRectZero style:UITableViewStylePlain];
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 82.f;
self.tableView.dataSource = self;
[self.tableView registerClass:[TextFieldTableViewCell class] forCellReuseIdentifier:TSTTextFieldTableViewCellIdentifier];
self.tableView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.tableView];
[self.tableView setContentInset:UIEdgeInsetsMake(20, 0, 0, -20)];
[self.tableView setSeparatorStyle:UITableViewCellSeparatorStyleNone];
if (@available(iOS 11.0, *)) {
[self.tableView.topAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.topAnchor].active = YES;
} else {
[self.tableView.topAnchor constraintEqualToAnchor:self.topLayoutGuide.bottomAnchor].active = YES;
}
[self.tableView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;
[self.tableView.leadingAnchor constraintEqualToAnchor:self.view.leadingAnchor].active = YES;
[self.tableView.trailingAnchor constraintEqualToAnchor:self.view.trailingAnchor].active = YES;
[self setupDataModel];
}
#pragma mark - UITableViewDataSource
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:TSTTextFieldTableViewCellIdentifier];
if ([cell isKindOfClass:[TextFieldTableViewCell class]]) {
TextFieldTableViewCell *textFieldCell = (TextFieldTableViewCell*)cell;
textFieldCell.textField.tag = indexPath.row;
textFieldCell.textField.delegate = self;
if (indexPath.row < (NSInteger)self.strings.count) {
NSString *string = self.strings[indexPath.row];
textFieldCell.textFieldController.textInput.text = string;
}
textFieldCell.textFieldController.placeholderText = [NSString stringWithFormat:@"TextField #%lu", (long)indexPath.row];
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 20;
}
#pragma mark - UITextFieldDelegate
- (BOOL)textFieldShouldReturn:(UITextField *)textField {
[textField resignFirstResponder];
return NO;
}
- (void)textFieldDidEndEditing:(UITextField *)textField {
self.strings[textField.tag] = textField.text ?: @"";
}
#pragma mark - Example Data
- (void)setupDataModel {
self.strings = [NSMutableArray array];
for (int i = 0; i < 20; ++i) {
[self.strings addObject:@""];
}
}
@end
@implementation TextFieldsTableViewExample (CatalogByConvention)
+ (NSArray *)catalogBreadcrumbs {
return @[ @"Text Field", @"Table View" ];
}
+ (BOOL)catalogIsPrimaryDemo {
return NO;
}
+ (BOOL)catalogIsPresentable {
return NO;
}
@end
@implementation TextFieldTableViewCell
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
self.textField = [[MDCTextField alloc] initWithFrame:CGRectZero];
self.textField.translatesAutoresizingMaskIntoConstraints = NO;
[self addSubview:self.textField];
[self.textField.topAnchor constraintEqualToAnchor:self.topAnchor].active = YES;
[self.textField.bottomAnchor constraintEqualToAnchor:self.bottomAnchor].active = YES;
[self.textField.leadingAnchor constraintEqualToAnchor:self.leadingAnchor constant:8].active = YES;
[self.textField.trailingAnchor constraintEqualToAnchor:self.trailingAnchor constant:-8].active = YES;
_textFieldController = [[MDCTextInputControllerFilled alloc] initWithTextInput:self.textField];
}
return self;
}
@end