1+ //
2+ // EaseInputTipsView.m
3+ // Coding_iOS
4+ //
5+ // Created by Ease on 15/5/7.
6+ // Copyright (c) 2015年 Coding. All rights reserved.
7+ //
8+
9+ #import " EaseInputTipsView.h"
10+ #import " Login.h"
11+
12+ @interface EaseInputTipsView ()<UITableViewDataSource, UITableViewDelegate>
13+
14+ @property (strong , nonatomic ) UITableView *myTableView;
15+ @property (strong , nonatomic ) NSArray *dataList;
16+
17+ @property (strong , nonatomic ) NSArray *loginAllList, *emailAllList;
18+
19+ @end
20+
21+ @implementation EaseInputTipsView
22+
23+ + (instancetype )tipsViewWithType : (EaseInputTipsViewType)type {
24+ return [[self alloc ] initWithTipsType: type];
25+ }
26+
27+ - (instancetype )initWithTipsType : (EaseInputTipsViewType)type {
28+ self = [super initWithFrame: CGRectMake (kLoginPaddingLeftWidth , 0 , kScreen_Width -2 *kLoginPaddingLeftWidth , 120 )];
29+ if (self) {
30+ [self addRoundingCorners: UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii: CGSizeMake (2 , 2 )];
31+ [self setClipsToBounds: YES ];
32+ _myTableView = ({
33+ UITableView *tableView = [[UITableView alloc ] initWithFrame: self .bounds style: UITableViewStylePlain];
34+ tableView.backgroundColor = [UIColor colorWithWhite: 1.0 alpha: 0.9 ];
35+ tableView.dataSource = self;
36+ tableView.delegate = self;
37+ tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine;
38+ [self addSubview: tableView];
39+ [tableView mas_makeConstraints: ^(MASConstraintMaker *make) {
40+ make.edges .equalTo (self);
41+ }];
42+ tableView;
43+ });
44+ _type = type;
45+ _active = YES ;
46+ }
47+ return self;
48+ }
49+
50+ - (void )refresh {
51+ [self .myTableView reloadData ];
52+ self.hidden = self.dataList .count <= 0 || !_active;
53+ }
54+ #pragma mark SetM
55+
56+ - (void )setActive : (BOOL )active {
57+ _active = active;
58+ self.hidden = self.dataList .count <= 0 || !_active;
59+ }
60+
61+ - (void )setValueStr : (NSString *)valueStr {
62+ _valueStr = valueStr;
63+ if (_valueStr.length <= 0 ) {
64+ self.dataList = nil ;
65+ }else if ([_valueStr rangeOfString: @" @" ].location == NSNotFound ) {
66+ self.dataList = _type == EaseInputTipsViewTypeLogin? [self loginList ]: nil ;
67+ }else {
68+ self.dataList = [self emailList ];
69+ }
70+ [self refresh ];
71+ }
72+
73+ - (NSArray *)loginList {
74+ if (_valueStr.length <= 0 ) {
75+ return nil ;
76+ }
77+ NSString *tipStr = [_valueStr copy ];
78+ NSMutableArray *list = [NSMutableArray new ];
79+ [[self loginAllList ] enumerateObjectsUsingBlock: ^(NSString *obj, NSUInteger idx, BOOL *stop) {
80+ if ([obj rangeOfString: tipStr].location != NSNotFound ) {
81+ [list addObject: obj];
82+ }
83+ }];
84+ return list;
85+ }
86+
87+ - (NSArray *)emailList {
88+ if (_valueStr.length <= 0 ) {
89+ return nil ;
90+ }
91+ NSRange range_AT = [_valueStr rangeOfString: @" @" ];
92+ if (range_AT.location == NSNotFound ) {
93+ return nil ;
94+ }
95+ NSString *nameStr = [_valueStr substringToIndex: range_AT.location];
96+ NSString *tipStr = [_valueStr substringFromIndex: range_AT.location + range_AT.length];
97+ NSMutableArray *list = [NSMutableArray new ];
98+ [[self emailAllList ] enumerateObjectsUsingBlock: ^(NSString *obj, NSUInteger idx, BOOL *stop) {
99+ if (tipStr.length <= 0 || [obj rangeOfString: tipStr].location != NSNotFound ) {
100+ [list addObject: [nameStr stringByAppendingFormat: @" @%@ " , obj]];
101+ }
102+ }];
103+ return list;
104+ }
105+
106+ - (NSArray *)loginAllList {
107+ if (!_loginAllList) {
108+ _loginAllList = [[Login readLoginDataList ] allKeys ];
109+ }
110+ return _loginAllList;
111+ }
112+ - (NSArray *)emailAllList {
113+ if (!_emailAllList) {
114+ NSString *emailListStr = @" qq.com, 163.com, gmail.com, 126.com, sina.com, sohu.com, hotmail.com, tom.com, sina.cn, foxmail.com, yeah.net, vip.qq.com, 139.com, live.cn, outlook.com, aliyun.com, yahoo.com, live.com, icloud.com, msn.com, 21cn.com, 189.cn, me.com, vip.sina.com, msn.cn, sina.com.cn" ;
115+
116+ _emailAllList = [emailListStr componentsSeparatedByString: @" , " ];
117+ }
118+ return _emailAllList;
119+ }
120+
121+ #pragma mark Table
122+ - (NSInteger )tableView : (UITableView *)tableView numberOfRowsInSection : (NSInteger )section {
123+ return _dataList.count ;
124+ }
125+
126+ - (UITableViewCell *)tableView : (UITableView *)tableView cellForRowAtIndexPath : (NSIndexPath *)indexPath {
127+ static NSString *CellIdentifier = @" EaseInputTipsViewCell" ;
128+ UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: CellIdentifier];
129+ if (!cell) {
130+ cell = [[UITableViewCell alloc ] initWithStyle: UITableViewCellStyleDefault reuseIdentifier: CellIdentifier];
131+ cell.backgroundColor = [UIColor clearColor ];
132+ cell.textLabel .font = [UIFont systemFontOfSize: 14 ];
133+ cell.textLabel .textColor = [UIColor colorWithHexString: @" 0x222222" ];
134+ }
135+ cell.textLabel .text = [_dataList objectAtIndex: indexPath.row];
136+ return cell;
137+ }
138+
139+ - (void )tableView : (UITableView *)tableView didSelectRowAtIndexPath : (NSIndexPath *)indexPath {
140+ [tableView deselectRowAtIndexPath: indexPath animated: YES ];
141+ if (self.selectedStringBlock && self.dataList .count > indexPath.row ) {
142+ self.selectedStringBlock ([self .dataList objectAtIndex: indexPath.row]);
143+ }
144+ }
145+
146+ - (CGFloat)tableView : (UITableView *)tableView heightForRowAtIndexPath : (NSIndexPath *)indexPath {
147+ return 35 ;
148+ }
149+
150+ @end
0 commit comments