mirror of
https://github.com/samuelclay/NewsBlur.git
synced 2025-08-05 16:58:59 +00:00

- Since the UIPageViewController approach to paging had multiple issues that were proving impossible to work around, I decided to revert to the old UIScrollView-based approach.
104 lines
3.1 KiB
Objective-C
104 lines
3.1 KiB
Objective-C
//
|
|
// FontListViewController.m
|
|
// NewsBlur
|
|
//
|
|
// Created by David Sinclair on 2015-10-30.
|
|
// Copyright © 2015 NewsBlur. All rights reserved.
|
|
//
|
|
|
|
#import "FontListViewController.h"
|
|
#import "MenuTableViewCell.h"
|
|
#import "NewsBlurAppDelegate.h"
|
|
#import "NewsBlur-Swift.h"
|
|
|
|
@interface FontListViewController ()
|
|
|
|
@property (nonatomic, strong) NSIndexPath *selectedIndexPath;
|
|
|
|
@end
|
|
|
|
@implementation FontListViewController
|
|
|
|
- (void)viewDidLoad {
|
|
[super viewDidLoad];
|
|
|
|
self.fontTableView.backgroundColor = UIColorFromRGB(0xECEEEA);
|
|
self.fontTableView.separatorColor = UIColorFromRGB(0x909090);
|
|
|
|
// eliminate extra separators at bottom of menu, if any
|
|
self.fontTableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
|
|
}
|
|
|
|
- (void)viewWillAppear:(BOOL)animated {
|
|
[super viewWillAppear:animated];
|
|
|
|
self.title = @"Font";
|
|
}
|
|
|
|
- (void)viewDidAppear:(BOOL)animated {
|
|
[super viewDidAppear:animated];
|
|
|
|
CGSize contentSize = self.fontTableView.contentSize;
|
|
contentSize.height += self.fontTableView.frame.origin.y * 2;
|
|
|
|
self.navigationController.preferredContentSize = contentSize;
|
|
self.fontTableView.scrollEnabled = contentSize.height > self.view.frame.size.height;
|
|
}
|
|
|
|
#pragma mark - Table view data source
|
|
|
|
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
|
return self.fonts.count;
|
|
}
|
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
static NSString *CellIndentifier = @"FontCell";
|
|
|
|
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIndentifier];
|
|
NSDictionary *font = self.fonts[indexPath.row];
|
|
|
|
if (!cell) {
|
|
cell = [[MenuTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIndentifier];
|
|
}
|
|
|
|
cell.textLabel.attributedText = font[@"name"];
|
|
|
|
NSString *fontStyle = [[NSUserDefaults standardUserDefaults] stringForKey:@"fontStyle"];
|
|
|
|
if (!fontStyle) {
|
|
fontStyle = @"GothamNarrow-Book";
|
|
}
|
|
|
|
if ([font[@"style"] isEqualToString:fontStyle]) {
|
|
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
self.selectedIndexPath = indexPath;
|
|
}
|
|
|
|
return cell;
|
|
}
|
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
return 38.0;
|
|
}
|
|
|
|
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
|
|
NewsBlurAppDelegate *appDelegate = [NewsBlurAppDelegate sharedAppDelegate];
|
|
NSDictionary *font = self.fonts[indexPath.row];
|
|
NSString *style = font[@"style"];
|
|
|
|
if (self.selectedIndexPath) {
|
|
MenuTableViewCell *cell = [self.fontTableView cellForRowAtIndexPath:self.selectedIndexPath];
|
|
cell.accessoryType = UITableViewCellAccessoryNone;
|
|
}
|
|
|
|
MenuTableViewCell *cell = [self.fontTableView cellForRowAtIndexPath:indexPath];
|
|
cell.accessoryType = UITableViewCellAccessoryCheckmark;
|
|
|
|
self.selectedIndexPath = indexPath;
|
|
|
|
[appDelegate.storyPagesViewController setFontStyle:style];
|
|
|
|
[tableView deselectRowAtIndexPath:indexPath animated:YES];
|
|
}
|
|
|
|
@end
|