Commit b178f3ac authored by luyueming's avatar luyueming

替换

parent b9d5e5ed
//
// GMToFaceCommonEmptyView.h
// GMAILab
//
// Created by 卢悦明 on 2020/5/9.
//
#import <UIKit/UIKit.h>
#import "GMLibraryHeader.h"
typedef NS_ENUM(NSInteger, GMToFaceCommonEmptyViewType) {
GMToFaceCommonEmptyViewTypeEmpty,//无数据
GMToFaceCommonEmptyViewTypeError//错误页面
};
@protocol GMToFaceCommonEmptyViewDelegate <NSObject>
- (void)emptyViewDidClickReload;
@end
@interface GMToFaceCommonEmptyView : UIView
/** 占位图 */
@property (nonatomic, strong) GMImageView *emptyImg;
/** 占位文字 */
@property (nonatomic, strong) GMLabel *emptyLabel;
/** 图片h宽高 */
@property (nonatomic, assign) CGSize emptyImgSize;
@property (nonatomic, assign) GMToFaceCommonEmptyViewType type;
@property (nonatomic, weak) id<GMToFaceCommonEmptyViewDelegate>delegate;
- (void)hide;
@end
//
// GMToFaceCommonEmptyView.m
// GMAILab
//
// Created by 卢悦明 on 2020/5/9.
//
#import "GMToFaceCommonEmptyView.h"
@interface GMToFaceCommonEmptyView ()
@property (nonatomic, strong) GMButton *tapBtn;
@end
@implementation GMToFaceCommonEmptyView
- (instancetype)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
self.backgroundColor = UIColor.whiteColor;
_emptyImg = [GMImageView new];
_emptyImg.contentMode = UIViewContentModeScaleAspectFit;
_emptyImg.image = [UIImage imageNamed:@"empty"];
[self addSubview:_emptyImg];
[_emptyImg mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.mas_equalTo(0);
make.centerY.mas_equalTo(-20);
make.size.mas_equalTo(CGSizeMake(175, 199));
}];
// 349/396
_emptyLabel = [GMLabel labelWithTextColor:UIColor.bodyText fontSize:15];
_emptyLabel.preferredMaxLayoutWidth = 300;
_emptyLabel.textAlignment = NSTextAlignmentCenter;
_emptyLabel.text = @"此处太寂寥,社区等你撩";
_emptyLabel.numberOfLines = 0;
[self addSubview:_emptyLabel];
[_emptyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(_emptyImg.mas_bottom).offset(-30);
make.centerX.mas_equalTo(0);
}];
[self addSubview:self.tapBtn];
[self.tapBtn mas_remakeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self);
make.width.mas_equalTo(150);
make.height.mas_equalTo(33);
make.top.mas_equalTo(_emptyImg.mas_bottom).offset(15);
}];
}
- (void)setEmptyImgSize:(CGSize)emptyImgSize {
_emptyImgSize = emptyImgSize;
[_emptyImg mas_updateConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(emptyImgSize);
}];
}
- (void)hide {
self.hidden = YES;
}
- (void)setType:(GMToFaceCommonEmptyViewType)type {
self.hidden = NO;
switch (type) {
case GMToFaceCommonEmptyViewTypeEmpty:{
self.tapBtn.hidden = YES;
self.emptyImg.image = [UIImage imageNamed:@"empty"];
self.emptyLabel.text = @"此处太寂寥,社区等你撩";
// self.emptyImgSize = CGSizeMake(175, 199);
break;
}
case GMToFaceCommonEmptyViewTypeError:{
self.tapBtn.hidden = NO;
self.emptyImg.image = [UIImage imageNamed:@"network_failed"];
self.emptyLabel.text = @"原谅我一看到美人就不淡定";
}
default:
break;
}
}
- (void)reloadBtnTap {
self.hidden = YES;
if ([self.delegate respondsToSelector:@selector(emptyViewDidClickReload)]) {
[self.delegate emptyViewDidClickReload];
}
}
- (GMButton *)tapBtn {
if (!_tapBtn) {
_tapBtn = [GMButton buttonWithCustomType:GMButtonTypeRedSemicircleGradient];
_tapBtn.hidden = YES;
[_tapBtn setTitle:@"重新加载" forState:UIControlStateNormal];
_tapBtn.titleLabel.font = [UIFont gmFont:16];
[_tapBtn setTitleColor:UIColor.bodyText forState:UIControlStateNormal];
[_tapBtn addTarget:self action:@selector(reloadBtnTap) forControlEvents:UIControlEventTouchUpInside];
}
return _tapBtn;
}
@end
//
// GMSearchNavigationView.h
// Gengmei
//
// Created by ioszhb on 2019/2/1.
// Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//
#import "GMLibraryHeader.h"
@protocol GMSearchNavigationViewDelegate;
@interface GMAISearchNavigationView : GMView
@property (nonatomic, assign) id<GMSearchNavigationViewDelegate> delegate;
@property (nonatomic, assign) BOOL showCancelButton;
@property (nonatomic, strong) UITextField *textField;
- (void)setShowCancelButton:(BOOL)showCancelButton animated:(BOOL)animated;
/**
* @brief 重了写该方法,以让搜索栏开始、停止输入
*
*/
- (BOOL)becomeFirstResponder;
- (BOOL)resignFirstResponder;
@end
@protocol GMSearchNavigationViewDelegate <NSObject>
- (void)searchNavigationCancelButtonClick;
@end
//
// GMAISearchNavigationView.m
// Gengmei
//
// Created by ioszhb on 2019/2/1.
// Copyright © 2019 更美互动信息科技有限公司. All rights reserved.
//
#import "GMAISearchNavigationView.h"
@interface GMAISearchNavigationView ()<UITextFieldDelegate>
@property (nonatomic, strong) GMButton *cancelButton;
/// textFiledCover
@property (nonatomic, strong) GMView *textCoverView;
@end
@implementation GMAISearchNavigationView
- (void)setup {
[super setup];
[self setupSubviews];
[self setupConstraints];
}
- (void)setupSubviews {
[self addSubview:self.textField];
[self addSubview:self.cancelButton];
[self.textField addSubview:self.textCoverView];
}
- (void)setupConstraints {
[self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(6);
make.bottom.mas_equalTo(-6);
make.left.mas_equalTo(20);
}];
[self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(self.textField.mas_right).offset(20);
make.right.mas_equalTo(-20);
make.top.mas_equalTo(0);
make.bottom.mas_equalTo(0);
make.width.mas_equalTo(32);
}];
[self.textCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
make.edges.mas_equalTo(0);
}];
}
- (void)updateSuberConstraints {
[self.cancelButton mas_updateConstraints:^(MASConstraintMaker *make) {
make.right.mas_equalTo(_showCancelButton ? -20 : 0);
make.width.mas_equalTo(_showCancelButton ? 32 : 0);
}];
}
#pragma mark - Setter
- (void)setShowCancelButton:(BOOL)showCancelButton{
[self setShowCancelButton:showCancelButton animated:YES];
}
- (void)setShowCancelButton:(BOOL)showCancelButton animated:(BOOL)animated{
_showCancelButton = showCancelButton;
[self updateSuberConstraints];
if (animated) {
[UIView animateWithDuration:0.2 animations:^{
[self layoutIfNeeded];
}];
}
}
#pragma mark - Action
- (void)cancelAction {
if ([self.delegate respondsToSelector:@selector(searchNavigationCancelButtonClick)]) {
[self.delegate searchNavigationCancelButtonClick];
}
}
/// 手动点击开始文本编辑
- (void)beiginTextEdit {
[Phobos track:@"on_click_navbar_search" attributes:@{@"page_name":self.pageName}];
[self.textField becomeFirstResponder];
}
#pragma mark - 重写
- (BOOL)resignFirstResponder{
self.showCancelButton = NO;
[_textField resignFirstResponder];
return [super resignFirstResponder];
}
- (BOOL)becomeFirstResponder{
self.showCancelButton = YES;
[_textField becomeFirstResponder];
return [super becomeFirstResponder];
}
#pragma mark - getter subviews
- (UITextField *)textField {
if (!_textField) {
_textField = [UITextField new];
_textField.delegate = self;
_textField.backgroundColor = UIColor.background;
_textField.enablesReturnKeyAutomatically = NO;
_textField.returnKeyType = UIReturnKeySearch;
_textField.clearButtonMode = UITextFieldViewModeWhileEditing;
_textField.layer.cornerRadius = 16;
_textField.layer.masksToBounds = YES;
_textField.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"搜索项目、美购、医生" attributes:@{
NSFontAttributeName:[UIFont systemFontOfSize:14],
NSForegroundColorAttributeName:UIColor.auxiliaryTextLight
}];
_textField.hasCloseButton = YES;
UIImage *imge = [UIImage imageNamed:@"home_new_search"];
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
UIImageView *leftView = [[UIImageView alloc] initWithImage:imge];
leftView.image = imge;
leftView.frame = CGRectMake(0, 0, imge.size.width, imge.size.height);
leftView.center = view.center;
[view addSubview:leftView];
_textField.leftView = view;
_textField.leftViewMode = UITextFieldViewModeAlways;
_textField.font = [UIFont gmFont:14];
_textField.textColor = [UIColor blackColor];
}
return _textField;
}
- (GMButton *)cancelButton {
if (!_cancelButton) {
_cancelButton = [GMButton new];
_cancelButton.backgroundColor = [UIColor whiteColor];
[_cancelButton addTarget:self action:@selector(cancelAction) forControlEvents:UIControlEventTouchUpInside];
[_cancelButton setTitle:@"取消" forState:UIControlStateNormal];
[_cancelButton setTitleColor:UIColor.headlineText forState:UIControlStateNormal];
_cancelButton.titleLabel.font = [UIFont gmFont:15];
}
return _cancelButton;
}
- (GMView *)textCoverView {
if (!_textCoverView) {
_textCoverView = [GMView new];
_textCoverView.userInteractionEnabled = YES;
_textCoverView.backgroundColor = [UIColor clearColor];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(beiginTextEdit)];
[_textCoverView addGestureRecognizer:tapGesture];
}
return _textCoverView;
}
@end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment