@@ -72,6 +72,12 @@ - (void)dealloc {
7272 _searchHistoryView.delegate = nil ;
7373}
7474
75+ - (NSArray *)titlesArray {
76+ if (!_titlesArray) {
77+ _titlesArray = @[@" 项目" , @" 任务" , @" 讨论" , @" 冒泡" , @" 文档" , @" 用户" , @" 合并请求" , @" Pull 请求" ];
78+ }
79+ return _titlesArray;
80+ }
7581
7682- (void )setActive : (BOOL )visible animated : (BOOL )animated {
7783
@@ -145,14 +151,6 @@ - (void)setActive:(BOOL)visible animated:(BOOL)animated {
145151- (void )initSearchResultsTableView {
146152 if (!self.searchResultView ) {
147153 self.searchResultView = [[UIView alloc ] initWithFrame: _contentView.bounds];
148- self.titlesArray = @[@" 项目" ,
149- @" 任务" ,
150- @" 讨论" ,
151- @" 冒泡" ,
152- @" 文档" ,
153- @" 用户" ,
154- @" 合并请求" ,
155- @" pull 请求" ];
156154 // 添加myCarousel
157155 self.myCarousel = ({
158156 CGRect iFrame = _contentView.bounds ;
@@ -196,76 +194,118 @@ - (void)initSearchHistoryView {
196194 self.searchBar .delegate =self;
197195 [self registerForKeyboardNotifications ];
198196 }
199-
200197 [[_searchHistoryView subviews ] makeObjectsPerformSelector: @selector (removeFromSuperview )];
201-
202- {
203- // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreen_Width, 0.5)];
204- // view.backgroundColor = kColorDDD;
205- // [_searchHistoryView addSubview:view];
206- }
207198 NSArray *array = [CSSearchModel getSearchHistory ];
208- CGFloat imageLeft = 12 .0f ;
209- CGFloat textLeft = 34 .0f ;
210- CGFloat height = 44 .0f ;
211-
212- _historyHeight=height*(array.count +1 );
213- // set history list
214- [_searchHistoryView mas_remakeConstraints: ^(MASConstraintMaker *make) {
215- make.top .mas_equalTo (@0 );
216- make.left .mas_equalTo (@0 );
217- make.width .mas_equalTo (kScreen_Width );
218- make.height .mas_equalTo (_historyHeight);
219- }];
220- _searchHistoryView.contentSize = CGSizeMake (kScreen_Width , _historyHeight);
221-
222-
223- for (int i = 0 ; i < array.count ; i++) {
224-
225- UILabel *lblHistory = [[UILabel alloc ] initWithFrame: CGRectMake (textLeft, i * height, kScreen_Width - textLeft, height)];
226- lblHistory.userInteractionEnabled = YES ;
227- lblHistory.font = [UIFont systemFontOfSize: 14 ];
228- lblHistory.textColor = kColor222 ;
229- lblHistory.text = array[i];
230-
231- UIImageView *leftView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 15 , 15 )];
232- leftView.left = 12 ;
233- leftView.centerY = lblHistory.centerY ;
234- leftView.image = [UIImage imageNamed: @" icon_search_clock" ];
235-
236- UIImageView *rightImageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 14 , 14 )];
237- rightImageView.right = kScreen_Width - 12 ;
238- rightImageView.centerY = lblHistory.centerY ;
239- rightImageView.image = [UIImage imageNamed: @" icon_arrow_searchHistory" ];
240-
241- UIView *view = [[UIView alloc ] initWithFrame: CGRectMake (imageLeft, (i + 1 ) * height, kScreen_Width - imageLeft, 0.5 )];
242- view.backgroundColor = kColorDDD ;
243-
244- UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (didClickedHistory: )];
245- [lblHistory addGestureRecognizer: tapGestureRecognizer];
246-
247- [_searchHistoryView addSubview: lblHistory];
248- [_searchHistoryView addSubview: leftView];
249- [_searchHistoryView addSubview: rightImageView];
250- [_searchHistoryView addSubview: view];
251- }
252-
253- if (array.count ) {
254-
255- UIButton *btnClean = [UIButton buttonWithType: UIButtonTypeCustom];
256- btnClean.titleLabel .font = [UIFont systemFontOfSize: 14 ];
257- [btnClean setTitle: @" 清除搜索历史" forState: UIControlStateNormal];
258- [btnClean setTitleColor: [UIColor colorWithHexString: @" 0x1bbf75" ] forState: UIControlStateNormal];
259- [btnClean setFrame: CGRectMake (0 , array.count * height, kScreen_Width , height)];
260- [_searchHistoryView addSubview: btnClean];
261- [btnClean addTarget: self action: @selector (didCLickedCleanSearchHistory: ) forControlEvents: UIControlEventTouchUpInside];
199+ if (array.count > 0 ) {
200+ CGFloat imageLeft = 12 .0f ;
201+ CGFloat textLeft = 34 .0f ;
202+ CGFloat height = 44 .0f ;
203+ _historyHeight=height*(array.count +1 );
204+ // set history list
205+ [_searchHistoryView mas_remakeConstraints: ^(MASConstraintMaker *make) {
206+ make.top .mas_equalTo (@0 );
207+ make.left .mas_equalTo (@0 );
208+ make.width .mas_equalTo (kScreen_Width );
209+ make.height .mas_equalTo (_historyHeight);
210+ }];
211+ _searchHistoryView.contentSize = CGSizeMake (kScreen_Width , _historyHeight);
212+ for (int i = 0 ; i < array.count ; i++) {
213+ UILabel *lblHistory = [[UILabel alloc ] initWithFrame: CGRectMake (textLeft, i * height, kScreen_Width - textLeft, height)];
214+ lblHistory.userInteractionEnabled = YES ;
215+ lblHistory.font = [UIFont systemFontOfSize: 14 ];
216+ lblHistory.textColor = kColor222 ;
217+ lblHistory.text = array[i];
218+
219+ UIImageView *leftView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 15 , 15 )];
220+ leftView.left = 12 ;
221+ leftView.centerY = lblHistory.centerY ;
222+ leftView.image = [UIImage imageNamed: @" icon_search_clock" ];
223+
224+ UIImageView *rightImageView = [[UIImageView alloc ] initWithFrame: CGRectMake (0 , 0 , 14 , 14 )];
225+ rightImageView.right = kScreen_Width - 12 ;
226+ rightImageView.centerY = lblHistory.centerY ;
227+ rightImageView.image = [UIImage imageNamed: @" icon_arrow_searchHistory" ];
228+
229+ UIView *view = [[UIView alloc ] initWithFrame: CGRectMake (imageLeft, (i + 1 ) * height, kScreen_Width - imageLeft, 0.5 )];
230+ view.backgroundColor = kColorDDD ;
231+
232+ UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc ] initWithTarget: self action: @selector (didClickedHistory: )];
233+ [lblHistory addGestureRecognizer: tapGestureRecognizer];
234+
235+ [_searchHistoryView addSubview: lblHistory];
236+ [_searchHistoryView addSubview: leftView];
237+ [_searchHistoryView addSubview: rightImageView];
238+ [_searchHistoryView addSubview: view];
239+ }
262240 {
241+ UIButton *btnClean = [UIButton buttonWithType: UIButtonTypeCustom];
242+ btnClean.titleLabel .font = [UIFont systemFontOfSize: 14 ];
243+ [btnClean setTitle: @" 清除搜索历史" forState: UIControlStateNormal];
244+ [btnClean setTitleColor: [UIColor colorWithHexString: @" 0x1bbf75" ] forState: UIControlStateNormal];
245+ [btnClean setFrame: CGRectMake (0 , array.count * height, kScreen_Width , height)];
246+ [_searchHistoryView addSubview: btnClean];
247+ [btnClean addTarget: self action: @selector (didCLickedCleanSearchHistory: ) forControlEvents: UIControlEventTouchUpInside];
263248 UIView *view = [[UIView alloc ] initWithFrame: CGRectMake (imageLeft, (array.count + 1 ) * height, kScreen_Width - imageLeft, 0.5 )];
264249 view.backgroundColor = kColorDDD ;
265250 [_searchHistoryView addSubview: view];
266251 }
252+
253+
254+ }else {
255+ _historyHeight = 240 ;
256+ // set history list
257+ [_searchHistoryView mas_remakeConstraints: ^(MASConstraintMaker *make) {
258+ make.top .mas_equalTo (@0 );
259+ make.left .mas_equalTo (@0 );
260+ make.width .mas_equalTo (kScreen_Width );
261+ make.height .mas_equalTo (_historyHeight);
262+ }];
263+ _searchHistoryView.contentSize = CGSizeMake (kScreen_Width , _historyHeight);
264+ CGFloat tipVWidth = 180 ;
265+ UIView *tipV = [UIView new ];
266+ UILabel *titleL = [UILabel labelWithSystemFontSize: 14 textColorHexString: @" 0x999999" ];
267+ titleL.text = @" 搜索更多内容" ;
268+ UIView *lineV = [UIView new ];
269+ lineV.backgroundColor = kColorDDD ;
270+ [tipV addSubview: titleL];
271+ [tipV addSubview: lineV];
272+ [titleL mas_makeConstraints: ^(MASConstraintMaker *make) {
273+ make.centerX .equalTo (tipV);
274+ make.top .equalTo (tipV).offset (50 );
275+ }];
276+ [lineV mas_makeConstraints: ^(MASConstraintMaker *make) {
277+ make.left .right .equalTo (tipV);
278+ make.top .equalTo (titleL.mas_bottom ).offset (15 );
279+ make.height .mas_equalTo (1 );
280+ }];
281+ NSArray *imageArray = @[@" project" , @" task" , @" topic" , @" tweet" , @" file" , @" user" , @" mr" , @" pr" ];
282+ CGFloat imageWidth = 20 ;
283+ CGFloat paddingWidth = (tipVWidth - 4 * 20 )/ 3 ;
284+ for (int index = 0 ; index < self.titlesArray .count && index < imageArray.count ; index++) {
285+ UIImageView *imageV = [[UIImageView alloc ] initWithImage: [UIImage imageNamed: [NSString stringWithFormat: @" search_icon_%@ " , imageArray[index]]]];
286+ UILabel *label = [UILabel labelWithSystemFontSize: 11 textColorHexString: @" 0x999999" ];
287+ label.text = self.titlesArray [index];
288+ [tipV addSubview: imageV];
289+ [tipV addSubview: label];
290+ [imageV mas_makeConstraints: ^(MASConstraintMaker *make) {
291+ make.size .mas_equalTo (CGSizeMake (imageWidth, imageWidth));
292+ make.top .equalTo (lineV.mas_bottom ).offset (20 + 65 * (index / 4 ));
293+ make.left .equalTo (tipV).offset ((paddingWidth + imageWidth) * (index % 4 ));
294+ }];
295+ [label mas_makeConstraints: ^(MASConstraintMaker *make) {
296+ make.top .equalTo (imageV.mas_bottom ).offset (10 );
297+ make.centerX .equalTo (imageV);
298+ }];
299+ }
300+ [_searchHistoryView addSubview: tipV];
301+ [tipV mas_makeConstraints: ^(MASConstraintMaker *make) {
302+ make.top .equalTo (_searchHistoryView);
303+ make.left .equalTo (_searchHistoryView).offset ((kScreen_Width - tipVWidth)/ 2 );
304+ make.size .mas_equalTo (CGSizeMake (tipVWidth, _historyHeight));
305+ }];
306+ // tipV.backgroundColor = [UIColor yellowColor];
307+
267308 }
268-
269309}
270310
271311#pragma mark - event
0 commit comments