CNLiveArticleFontViewController.m
4.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
//
// CNLiveArticleFontViewController.m
// CNLiveScioLive
//
// Created by CNLive-zxw on 2018/9/20.
// Copyright © 2018年 CNLive. All rights reserved.
//
#import "CNLiveArticleFontViewController.h"
@interface CNLiveArticleFontViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, assign) NSInteger selectFont;
@property (nonatomic, strong) NSArray *fontArray;
@end
@implementation CNLiveArticleFontViewController
static NSString *tableViewCell = @"UITableViewCell";
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
_selectFont = [[NSUserDefaults standardUserDefaults] integerForKey:@"FontSize"];
[self.tableView reloadData];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self setUpNavigationBar];
[self.view addSubview:self.tableView];
}
#pragma mark - UI
- (void)setUpNavigationBar{
self.navigationController.navigationBar.barTintColor = Color_Blue;
[self.navigationController.navigationBar setTitleTextAttributes:@{NSForegroundColorAttributeName:[UIColor whiteColor]}];
//左
UIButton *headerButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 44)];
headerButton.layer.cornerRadius = 2.0;
headerButton.layer.masksToBounds = true;
[headerButton setImage:[UIImage imageNamed:@"cnlive_white_back"] forState:UIControlStateNormal];
[headerButton addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:headerButton];
self.navigationItem.title = CustomStr(@"FontSettings");
}
#pragma mark - UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
return 40;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
return 0.00000001f;
}
#pragma mark - UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return self.fontArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:tableViewCell];
if (!cell) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:tableViewCell];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = HEXCOLOR(0x333333);
cell.textLabel.font = [UIFont systemFontOfSize:15];
cell.textLabel.text = self.fontArray[indexPath.row];
if (_selectFont == indexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
return cell;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *headerView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, MainScreenWidth, 10)];
headerView.backgroundColor = HEXCOLOR(0xebebeb);
return headerView;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInteger:indexPath.row] forKey:@"FontSize"];
_selectFont = indexPath.row;
[self.tableView reloadData];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - Lazy Laoding
- (UITableView *)tableView{
if(!_tableView){
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainScreenWidth, MainScreenHeight - NavBarHeight) style:UITableViewStyleGrouped];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.estimatedRowHeight = 0;
_tableView.estimatedSectionHeaderHeight = 0;
_tableView.estimatedSectionFooterHeight = 0;
_tableView.backgroundColor = HEXCOLOR(0xebebeb);
[_tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:tableViewCell];
}
return _tableView;
}
- (NSArray *)fontArray{
if(!_fontArray){
_fontArray = [[NSArray alloc] initWithObjects:CustomStr(@"Small"), CustomStr(@"Medium"), CustomStr(@"Big"), nil];
}
return _fontArray;
}
@end