-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathUISearchBar+MUSearchBar.m
59 lines (43 loc) · 1.88 KB
/
UISearchBar+MUSearchBar.m
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
//
// UISearchBar+MUSearchBar.m
// MUSearch
//
// Created by windyer on 2016/12/29.
// Copyright © 2016年 wonhigh. All rights reserved.
//
#import "UISearchBar+MUSearchBar.h"
@implementation UISearchBar (MUSearchBar)
- (void)setSearchBarPlaceholdePositon {
SEL centerSelector = NSSelectorFromString([NSString stringWithFormat:@"%@%@", @"setCenter", @"Placeholder:"]);
if ([self respondsToSelector:centerSelector]) {
BOOL centeredPlaceholder = NO;
NSMethodSignature *signature = [[UISearchBar class] instanceMethodSignatureForSelector:centerSelector];
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:self];
[invocation setSelector:centerSelector];
[invocation setArgument:¢eredPlaceholder atIndex:2];
[invocation invoke];
}
}
- (void)setSearchBarBackgroudColorWith:(UISearchBar *)searchBar {
UIImage* searchBarBg = [self GetImageWithColor:[UIColor clearColor] andHeight:32.0f];
//设置背景图片
[searchBar setBackgroundImage:searchBarBg];
//设置背景色
[searchBar setBackgroundColor:[UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1]];
//设置文本框背景
[searchBar setSearchFieldBackgroundImage:searchBarBg forState:UIControlStateNormal];
[UIColor colorWithRed:235/255.0 green:235/255.0 blue:235/255.0 alpha:1];
}
- (UIImage*) GetImageWithColor:(UIColor*)color andHeight:(CGFloat)height
{
CGRect r= CGRectMake(0.0f, 0.0f, 1.0f, height);
UIGraphicsBeginImageContext(r.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, r);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return img;
}
@end