Skip to content

Commit 88a055a

Browse files
committed
编辑标签 - 可以更换颜色
1 parent a9e4ed0 commit 88a055a

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

Coding_iOS/Controllers/ResetLabelViewController.m

+21-13
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
#import "TPKeyboardAvoidingTableView.h"
1212
#import "Coding_NetAPIManager.h"
1313
#import "ProjectTag.h"
14+
#import "EditColorViewController.h"
1415

1516
#define kCellIdentifier_ResetLabelCell @"ResetLabelCell"
1617

1718
@interface ResetLabelViewController () <UITableViewDataSource, UITableViewDelegate, UITextFieldDelegate>
18-
{
19-
NSString *_tempStr;
20-
}
19+
@property (strong, nonatomic) NSString *tempStr;
20+
2121
@property (strong, nonatomic) TPKeyboardAvoidingTableView *myTableView;
2222

2323
@property (nonatomic, weak) UITextField *mCurrentTextField;
@@ -29,12 +29,9 @@ @implementation ResetLabelViewController
2929
- (void)viewDidLoad {
3030
[super viewDidLoad];
3131
// Do any additional setup after loading the view.
32-
self.title = @"重命名标签";
33-
self.navigationController.title = @"重命名标签";
34-
32+
self.title = @"编辑标签";
3533
self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithBtnTitle:@"取消" target:self action:@selector(cancelBtnClick)];
3634
self.navigationItem.rightBarButtonItem = [UIBarButtonItem itemWithBtnTitle:@"完成" target:self action:@selector(okBtnClick)];
37-
self.navigationItem.rightBarButtonItem.enabled = FALSE;
3835

3936
self.view.backgroundColor = kColorTableSectionBg;
4037

@@ -53,6 +50,12 @@ - (void)viewDidLoad {
5350
});
5451
}
5552

53+
- (void)viewWillAppear:(BOOL)animated{
54+
[super viewWillAppear:animated];
55+
_tempStr = _ptLabel.name;
56+
[_myTableView reloadData];
57+
}
58+
5659
- (void)didReceiveMemoryWarning {
5760
[super didReceiveMemoryWarning];
5861
// Dispose of any resources that can be recreated.
@@ -100,8 +103,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
100103
[tableView addLineforPlainCell:cell forRowAtIndexPath:indexPath withLeftSpace:kPaddingLeftWidth];
101104
cell.labelField.delegate = self;
102105
[cell.labelField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
106+
[cell.colorBtn addTarget:self action:@selector(colorBtnClick:) forControlEvents:UIControlEventTouchUpInside];
103107
cell.backgroundColor = kColorTableBG;
104108
cell.labelField.text = _ptLabel.name;
109+
cell.colorBtn.backgroundColor = [UIColor colorWithHexString:[_ptLabel.color stringByReplacingOccurrencesOfString:@"#" withString:@"0x"]];
105110
return cell;
106111
}
107112

@@ -116,6 +121,13 @@ - (BOOL)tableView:(UITableView *)tableView shouldHighlightRowAtIndexPath:(NSInde
116121
return FALSE;
117122
}
118123

124+
#pragma mark - color
125+
- (void)colorBtnClick:(UIButton *)sender{
126+
EditColorViewController *vc = [EditColorViewController new];
127+
vc.curTag = _ptLabel;
128+
[self.navigationController pushViewController:vc animated:YES];
129+
}
130+
119131
#pragma mark - UITextFieldDelegate
120132
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
121133
{
@@ -134,12 +146,8 @@ - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRang
134146

135147
- (void)textFieldDidChange:(UITextField *)textField
136148
{
137-
_tempStr = textField.text;
138-
if (_tempStr.length > 0) {
139-
self.navigationItem.rightBarButtonItem.enabled = [_tempStr isEqualToString:_ptLabel.name] ? FALSE : TRUE;
140-
} else {
141-
self.navigationItem.rightBarButtonItem.enabled = FALSE;
142-
}
149+
self.tempStr = textField.text;
150+
self.navigationItem.rightBarButtonItem.enabled = _tempStr.length > 0;;
143151
}
144152

145153
- (BOOL)textFieldShouldReturn:(UITextField *)textField

Coding_iOS/Views/Cell/ResetLabelCell.h

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
@interface ResetLabelCell : UITableViewCell
1212

1313
@property (strong, nonatomic) UITextField *labelField;
14+
@property (strong, nonatomic) UIButton *colorBtn;
1415

1516
+ (CGFloat)cellHeight;
1617

Coding_iOS/Views/Cell/ResetLabelCell.m

+9-1
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,19 @@ - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reus
1717
self.accessoryType = UITableViewCellAccessoryNone;
1818
self.backgroundColor = [UIColor clearColor];
1919
// Initialization code
20+
if (!_colorBtn) {
21+
_colorBtn = [[UIButton alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 7, 30, 30)];
22+
_colorBtn.layer.masksToBounds = YES;
23+
_colorBtn.layer.cornerRadius = 4;
24+
[_colorBtn setImage:[UIImage imageNamed:@"tag_button_editColor"] forState:UIControlStateNormal];
25+
[self.contentView addSubview:_colorBtn];
26+
}
2027
if (!_labelField) {
21-
_labelField = [[UITextField alloc] initWithFrame:CGRectMake(kPaddingLeftWidth, 0, (kScreen_Width - kPaddingLeftWidth * 2), 44)];
28+
_labelField = [[UITextField alloc] initWithFrame:CGRectMake(CGRectGetMaxX(_colorBtn.frame) + 10, 0, (kScreen_Width - kPaddingLeftWidth - CGRectGetMaxX(_colorBtn.frame) - 10), 44)];
2229
_labelField.textColor = [UIColor colorWithHexString:@"0x222222"];
2330
_labelField.font = [UIFont systemFontOfSize:16];
2431
_labelField.clearButtonMode = UITextFieldViewModeWhileEditing;
32+
_labelField.placeholder = @"输入标签名称";
2533
[self.contentView addSubview:_labelField];
2634
}
2735
}

0 commit comments

Comments
 (0)