| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- //
- // CommonBarView.m
- // SeeTheDay
- //
- // Created by lww on 2022/6/25.
- // Rectangle 4
- #import "SearchCommonBarView.h"
- @interface SearchCommonBarView()<UITextFieldDelegate>
- @end
- @implementation SearchCommonBarView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- [self configUI];
- }
- return self;
- }
- -(void)configUI{
- self.backgroundColor = rgba(18, 23, 41, 1);
- self.bgView = [UIView new];
- [self addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.bottom.equalTo(self).offset(-6);
- make.left.right.equalTo(self);
- make.height.mas_equalTo(@36);
- }];
-
- self.searchBgView =[UIView new];
- self.searchBgView.backgroundColor = rgba(52, 56, 68, 1);
- self.searchBgView.layer.cornerRadius = 18;
- self.searchBgView.layer.masksToBounds = true;
- [self.bgView addSubview:self.searchBgView];
- [self.searchBgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.top.bottom.equalTo(self.bgView);
- make.left.equalTo(self.bgView).offset(20);
- make.right.equalTo(self.bgView).offset(-64);
- }];
-
- self.tipimageView = [UIImageView new];
- self.tipimageView.image = [UIImage imageNamed:@"Frame 9345"];
- [self.searchBgView addSubview:self.tipimageView];
- [self.tipimageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.searchBgView);
- make.left.equalTo(self.searchBgView).offset(12);
- make.size.mas_equalTo(CGSizeMake(20, 20));
- }];
-
-
- self.textField = [UITextField new];
- NSMutableAttributedString *attributedPlaceholder = [[NSMutableAttributedString alloc] initWithString:@"搜索"];
- [attributedPlaceholder addAttribute:NSForegroundColorAttributeName value:rgba(255, 255, 255, 0.4) range:NSMakeRange(0, attributedPlaceholder.length)];
- [attributedPlaceholder addAttribute:NSFontAttributeName value:[UIFont italicSystemFontOfSize:14.0] range:NSMakeRange(0, attributedPlaceholder.length)];
- self.textField.attributedPlaceholder = attributedPlaceholder;
- // self.textField.text = @"扫黑行动";
- self.textField.textColor = [UIColor whiteColor];
- self.textField.font = [UIFont systemFontOfSize:14];
- self.textField.delegate = self;
- [self.textField addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
- self.textField.returnKeyType = UIReturnKeySearch;
- [self.searchBgView addSubview:self.textField];
- [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.searchBgView);
- make.left.equalTo(self.tipimageView.mas_right).offset(8);
- make.height.right.equalTo(self.searchBgView);
- }];
-
-
- self.searchButton = [UIButton new];
- [self.searchButton setTitle:@"搜索" forState:UIControlStateNormal];
- self.searchButton.titleLabel.font = [UIFont systemFontOfSize:14];
- [self.searchButton setTitleColor:rgba(255, 212, 0, 1) forState:UIControlStateNormal];
- [self.searchButton addTarget:self action:@selector(searchBtnAction) forControlEvents:UIControlEventTouchUpInside];
- [self.bgView addSubview:self.searchButton];
- [self.searchButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.searchBgView);
- make.left.equalTo(self.searchBgView.mas_right).offset(16);
- }];
-
- }
- - (void)textFieldDidChange:(UITextField *)textField
- {
- if(textField.text.length>10){
- textField.text = [textField.text substringToIndex:10];
- }
- }
- -(void)searchBtnAction{
- if(self.searchAction && self.textField.text.length>0){
- self.searchAction(self.textField.text);
- }
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField{
- if (textField.text.length != 0) {
- self.searchAction(self.textField.text);
- }
- [textField resignFirstResponder];
- return YES;
- }
- @end
|