TDSearchBar.m 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. //
  2. // TDSearchBar.m
  3. // TheoryNetwork
  4. //
  5. // Created by tederen on 2019/9/23.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "TDSearchBar.h"
  9. @implementation TDSearchBar
  10. - (instancetype)init
  11. {
  12. self = [super init];
  13. if (self) {
  14. self.backgroundImage = [UIImage new];
  15. self.placeholder = @" 搜索";
  16. self.layer.cornerRadius = 5.f;
  17. self.layer.borderWidth = 0.5;
  18. self.layer.borderColor = [UIColor hexStringToColor:@"d8d8d8"].CGColor;
  19. UIImage *searchIcon = [UIImage imageNamed:@"sousuo"];
  20. [self setImage:searchIcon forSearchBarIcon:UISearchBarIconSearch state:UIControlStateNormal];
  21. for (UIView *view in self.subviews.lastObject.subviews.lastObject.subviews) {
  22. if([view isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
  23. UITextField *textField = (UITextField *)view;
  24. //设置输入框的背景颜色
  25. textField.clipsToBounds = YES;
  26. //设置输入字体颜色
  27. textField.textColor = kColorFromRGB(0x333333);
  28. //设置默认文字颜色
  29. textField.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:14];
  30. }
  31. }
  32. UIImage* clearImg = [UtilsTools imageWithColor:[UIColor clearColor] andHeight:20.f];
  33. [self setSearchFieldBackgroundImage:clearImg forState:UIControlStateNormal];
  34. }
  35. return self;
  36. }
  37. @end