material-components_materia.../components/Typography/examples/TypographyCustomFontViewController.m
Randall Li 2f29f00d86 Fixed some compiler warnings (#2426)
* Added warnings to examples.

* fixed some warnings

* using button sender parameter.

* use button sender in example

* use button sender in example

* removed sender from methods that don’t use it.

* removed sender from methods that don’t use it.

* use button sender in example

* use button sender in example

* use button sender in example

* use button sender in example

* Fixed init of header configurator to use passed in parameter

* removed unused API

* use button sender in example

* Revert "Added warnings to examples."

This reverts commit 91f0480f86cb609c47b00f1346f82de67c31c4e9.

* fixed example: Using the view controllers navigationItem rather than creating a new one.

* removed finished checks from animation blocks in examples.

* reverted id sender checks

* revert id sender check for Flexible header UINavigationBar

* revert clug

* revert clug

* addressing nits

* removed sender check for FeatureHighlightTypicalUseView

* more nits
2017-11-22 10:51:55 -05:00

162 lines
6.0 KiB
Objective-C

/*
Copyright 2017-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 "TypographyCustomFontViewController.h"
#import "MaterialTypography.h"
@implementation TypographyCustomFontViewController {
NSArray<NSString *> *_strings;
NSArray<NSString *> *_styleNames;
NSArray<UIFont *> *_styleFonts;
NSArray<NSNumber *> *_opacities;
}
static inline UIFont *customFont(MDCFontTextStyle style) {
UIFontDescriptor *descriptor = [UIFontDescriptor mdc_preferredFontDescriptorForMaterialTextStyle:style];
descriptor = [descriptor fontDescriptorWithFamily:@"American Typewriter"];
UIFont *font = [UIFont fontWithDescriptor:descriptor size:descriptor.pointSize];
return font;
};
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor whiteColor];
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
self.tableView.rowHeight = UITableViewAutomaticDimension;
self.tableView.estimatedRowHeight = 50.0;
_strings = @[
@"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
@"abcdefghijklmnopqrstuvwxyz",
@"0123456789"
];
_styleNames = @[
// Common UI fonts.
@"Headline Font",
@"Title Font",
@"Subhead Font",
@"Body 2 Font",
@"Body 1 Font",
@"Caption Font",
@"Button Font",
// Display fonts (extra large fonts)
@"Display 1 Font",
@"Display 2 Font",
@"Display 3 Font",
@"Display 4 Font"
];
_styleFonts = @[
customFont(MDCFontTextStyleHeadline),
customFont(MDCFontTextStyleTitle),
customFont(MDCFontTextStyleSubheadline),
customFont(MDCFontTextStyleBody2),
customFont(MDCFontTextStyleBody1),
customFont(MDCFontTextStyleCaption),
customFont(MDCFontTextStyleButton),
customFont(MDCFontTextStyleDisplay1),
customFont(MDCFontTextStyleDisplay2),
customFont(MDCFontTextStyleDisplay3),
customFont(MDCFontTextStyleDisplay4)
];
_opacities = @[
@([MDCTypography headlineFontOpacity]),
@([MDCTypography titleFontOpacity]),
@([MDCTypography subheadFontOpacity]),
@([MDCTypography body2FontOpacity]),
@([MDCTypography body1FontOpacity]),
@([MDCTypography captionFontOpacity]),
@([MDCTypography buttonFontOpacity]),
@([MDCTypography display1FontOpacity]),
@([MDCTypography display2FontOpacity]),
@([MDCTypography display3FontOpacity]),
@([MDCTypography display4FontOpacity])
];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(contentSizeCategoryDidChange:)
name:UIContentSizeCategoryDidChangeNotification
object:nil];
}
- (void)contentSizeCategoryDidChange:(NSNotification *)notification {
// Update font array to reflect new size category
_styleFonts = @[
customFont(MDCFontTextStyleHeadline),
customFont(MDCFontTextStyleTitle),
customFont(MDCFontTextStyleSubheadline),
customFont(MDCFontTextStyleBody2),
customFont(MDCFontTextStyleBody1),
customFont(MDCFontTextStyleCaption),
customFont(MDCFontTextStyleButton),
customFont(MDCFontTextStyleDisplay1),
customFont(MDCFontTextStyleDisplay2),
customFont(MDCFontTextStyleDisplay3),
customFont(MDCFontTextStyleDisplay4)
];
[self.tableView reloadData];
}
#pragma mark - UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return _strings.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return _styleFonts.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [self.tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:@"cell"];
}
cell.textLabel.text = _strings[indexPath.section];
cell.textLabel.font = _styleFonts[indexPath.row];
cell.textLabel.alpha = [_opacities[indexPath.row] floatValue];
cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
if (cell.textLabel.font.pointSize > 100 && indexPath.section == 0) {
cell.textLabel.text = @"ABCD";
}
cell.detailTextLabel.text = _styleNames[indexPath.row];
cell.detailTextLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleCaption1];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
#pragma mark - CatalogByConvention
+ (NSArray *)catalogBreadcrumbs {
return @[ @"Typography Custom Fonts", @"Material Font Styles" ];
}
+ (BOOL)catalogIsPrimaryDemo {
return NO;
}
@end