// // createSearchBarView.m // smartRhino // // Created by niuzhen on 2019/12/13. // Copyright © 2019 tederen. All rights reserved. // #import "createSearchBarView.h" @implementation createSearchBarView - (instancetype)init { if (self = [super init]) { [self setFrame:CGRectMake(0, 0, SCREEN_WIDTH, 50)]; self.backgroundColor = [UIColor whiteColor]; [self addSearchView]; } return self; } - (void)addSearchView { UIView * view = [UIView new]; view.backgroundColor = UIColorHex(F5F6F8); [self addSubview:view]; [view mas_makeConstraints:^(MASConstraintMaker *make) { make.edges.mas_offset(UIEdgeInsetsMake(10, 15, 10, 15)); }]; view.layer.cornerRadius = 15.f; view.layer.masksToBounds = YES; UILabel * searchL = [UILabel new]; NSTextAttachment *attach = [[NSTextAttachment alloc] init]; attach.image = [UIImage imageNamed:@"chatmsg_search_icon"]; attach.bounds = CGRectMake(0, -1, 12, 12); NSAttributedString *attachString = [NSAttributedString attributedStringWithAttachment:attach]; NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithAttributedString:attachString]; 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]}]; [string appendAttributedString:[[NSAttributedString alloc] initWithAttributedString:newString]]; searchL.attributedText = string; [view addSubview:searchL]; [searchL mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(view); }]; } @end