Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
110 lines (105 loc) · 5.02 KB

File metadata and controls

110 lines (105 loc) · 5.02 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
//
// EditColorViewController.m
// Coding_iOS
//
// Created by Ease on 16/2/19.
// Copyright © 2016年 Coding. All rights reserved.
//
#import "EditColorViewController.h"
#import "TPKeyboardAvoidingTableView.h"
#import "TagColorEditCell.h"
#import "TagColorDisplayCell.h"
@interface EditColorViewController ()<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView;
@property (strong, nonatomic) NSArray *colorList;
@end
@implementation EditColorViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.title = @"标签颜色";
_colorList = @[@{@"name": @"灰色",
@"value": @"#90A4AE"},
@{@"name": @"黄色",
@"value": @"#FFC107"},
@{@"name": @"红色",
@"value": @"#FF5722"},
@{@"name": @"绿色",
@"value": @"#4CAF50"},
@{@"name": @"蓝色",
@"value": @"#03A9F4"},
@{@"name": @"紫色",
@"value": @"#AB44BC"},
];
_myTableView = ({
TPKeyboardAvoidingTableView *tableView = [[TPKeyboardAvoidingTableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
tableView.backgroundColor = kColorTableSectionBg;
tableView.delegate = self;
tableView.dataSource = self;
[tableView registerClass:[TagColorEditCell class] forCellReuseIdentifier:kCellIdentifier_TagColorEditCell];
[tableView registerClass:[TagColorDisplayCell class] forCellReuseIdentifier:kCellIdentifier_TagColorDisplayCell];
tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
[self.view addSubview:tableView];
[tableView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.equalTo(self.view);
}];
tableView.estimatedRowHeight = 0;
tableView.estimatedSectionHeaderHeight = 0;
tableView.estimatedSectionFooterHeight = 0;
tableView;
});
}
#pragma matk Table
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return section == 0? 1: _colorList.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0) {
TagColorEditCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TagColorEditCell forIndexPath:indexPath];
cell.colorF.text = _curTag.color;
@weakify(self);
@weakify(cell);
[cell.colorF.rac_textSignal subscribeNext:^(NSString *value) {
if (![value hasPrefix:@"#"] || value.length != 7) {
return ;
}
UIColor *color = [UIColor colorWithHexString:[value stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]];
if (!color || ![[value uppercaseString] hasSuffix:[color hexStringFromColor]]) {
return ;
}
@strongify(self);
@strongify(cell);
self.curTag.color = [value uppercaseString];
cell.colorView.backgroundColor = color;
}];
cell.colorView.backgroundColor = [UIColor colorWithHexString:[_curTag.color stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]];
[cell.randomBtn addTarget:self action:@selector(randomColorBtnClicked) forControlEvents:UIControlEventTouchUpInside];
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
return cell;
}else{
TagColorDisplayCell *cell = [tableView dequeueReusableCellWithIdentifier:kCellIdentifier_TagColorDisplayCell forIndexPath:indexPath];
NSDictionary *colorDict = _colorList[indexPath.row];
cell.colorView.backgroundColor = [UIColor colorWithHexString:[colorDict[@"value"] stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]];
cell.colorL.text = colorDict[@"name"];
cell.accessoryType = [_curTag.color isEqualToString:colorDict[@"value"]]? UITableViewCellAccessoryCheckmark: UITableViewCellAccessoryNone;
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:CGRectGetMinX(cell.colorL.frame)];
return cell;
}
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
if (indexPath.section == 1) {
NSDictionary *colorDict = _colorList[indexPath.row];
_curTag.color = [colorDict[@"value"] uppercaseString];
[self.navigationController popViewControllerAnimated:YES];
}
}
#pragma mark Btn
- (void)randomColorBtnClicked{
_curTag.color = [NSString stringWithFormat:@"#%@", [[UIColor randomColor] hexStringFromColor]];
[self.myTableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationNone];
}
@end
Morty Proxy This is a proxified and sanitized view of the page, visit original site.