createSearchBarView.m 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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: 14],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. }
  43. @end