createSearchBarView.m 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. //
  2. // createSearchBarView.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2019/12/13.
  6. // Copyright © 2019 tederen. All rights reserved.
  7. //
  8. #import "createSearchBarView.h"
  9. @implementation createSearchBarView
  10. - (instancetype)init
  11. {
  12. if (self = [super init]) {
  13. [self setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)];
  14. self.backgroundColor = [UIColor whiteColor];
  15. [self addSearchView];
  16. }
  17. return self;
  18. }
  19. - (void)addSearchView
  20. {
  21. UIView * view = [UIView new];
  22. view.backgroundColor = UIColorHex(F5F6F8);
  23. [self addSubview:view];
  24. [view mas_makeConstraints:^(MASConstraintMaker *make) {
  25. make.edges.mas_offset(UIEdgeInsetsMake(10, 15, 10, 15));
  26. }];
  27. view.layer.cornerRadius = 15.f;
  28. view.layer.masksToBounds = YES;
  29. UILabel * searchL = [UILabel new];
  30. NSTextAttachment *attach = [[NSTextAttachment alloc] init];
  31. attach.image = [UIImage imageNamed:@"chatmsg_search_icon"];
  32. attach.bounds = CGRectMake(0, -1, 12, 12);
  33. NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach];
  34. NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:attachString];
  35. NSAttributedString * newString = [[NSAttributedString alloc] initWithString:@" 搜索" attributes:@{NSFontAttributeName: [UIFont fontWithName:@"PingFang SC" size: 13],NSForegroundColorAttributeName: [UIColor colorWithRed:171/255.0 green:172/255.0 blue:174/255.0 alpha:1.0]}];
  36. [string appendAttributedString:[[NSAttributedString alloc] initWithAttributedString:newString]];
  37. searchL.attributedText = string;
  38. [view addSubview:searchL];
  39. [searchL mas_makeConstraints:^(MASConstraintMaker *make) {
  40. make.center.mas_equalTo(view);
  41. }];
  42. WS(weakSelf);
  43. UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc] initWithActionBlock:^(id _Nonnull sender) {
  44. if (weakSelf.ClickBlock) {
  45. weakSelf.ClickBlock();
  46. }
  47. }];
  48. [self addGestureRecognizer:tap];
  49. }
  50. @end