12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- //
- // TDSearchBar.m
- // TheoryNetwork
- //
- // Created by tederen on 2019/9/23.
- // Copyright © 2019 tederen. All rights reserved.
- //
- #import "TDSearchBar.h"
- @implementation TDSearchBar
- - (instancetype)init
- {
- self = [super init];
- if (self) {
- self.backgroundImage = [UIImage new];
- self.placeholder = @" 搜索";
- self.layer.cornerRadius = 5.f;
- self.layer.borderWidth = 0.5;
- self.layer.borderColor = [UIColor hexStringToColor:@"d8d8d8"].CGColor;
- UIImage *searchIcon = [UIImage imageNamed:@"sousuo"];
- [self setImage:searchIcon forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
- for (UIView *view in self.subviews.lastObject.subviews.lastObject.subviews) {
- if([view isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
- UITextField *textField = (UITextField *)view;
- //设置输入框的背景颜色
- textField.clipsToBounds = YES;
- //设置输入字体颜色
- textField.textColor = kColorFromRGB(0x333333);
- //设置默认文字颜色
- textField.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14];
- }
- }
- UIImage* clearImg = [UtilsTools imageWithColor:[UIColor clearColor] andHeight:20.f];
- [self setSearchFieldBackgroundImage:clearImg forState:UIControlStateNormal];
- }
- return self;
- }
- @end
|