1 .h文件

@interface SearchNavView : UIView
@property (nonatomic, copy) void(^cancleBtnBlock)(void);
@property (nonatomic, copy) void(^textFiledEditingBlock)(NSString *contentStr);
@end

2 .m文件

#import "SearchNavView.h"
@interface SearchNavView()<UITextFieldDelegate>
@property (nonatomic, strong) UITextField *searchTextFiled;
@property (nonatomic, strong) UIButton *cancleBtn;
@end @implementation SearchNavView - (instancetype)initWithFrame:(CGRect)frame
{
if (self = [super initWithFrame:frame]) {
[self addSubview:self.searchTextFiled];
[self addSubview:self.cancleBtn];
_searchTextFiled.delegate = self;
}
return self;
}
- (void)layoutSubviews
{
[super layoutSubviews];
__weak typeof(self)weakself = self;
[self.searchTextFiled mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(weakself.mas_centerY);
make.left.equalTo(weakself.mas_left).offset( / WIDTH_6S_SCALE);
make.width.mas_equalTo( / WIDTH_6S_SCALE);
make.height.mas_equalTo( / HEIGHT_6S_SCALE);
}];
_searchTextFiled.layer.cornerRadius = ;
_searchTextFiled.layer.masksToBounds = YES;
[self.cancleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerY.equalTo(weakself.mas_centerY);
make.right.equalTo(weakself.mas_right).offset(- / WIDTH_6S_SCALE);
make.width.mas_equalTo( / WIDTH_6S_SCALE);
make.height.mas_equalTo( / HEIGHT_6S_SCALE);
}];
}
#pragma mark -UITextFieldDelegate
- (void)textFieldDidEndEditing:(UITextField *)textField
{
if (self.textFiledEditingBlock) {
self.textFiledEditingBlock(self.searchTextFiled.text);
}
}
#pragma mark - event
- (void)cancleBtnAction
{
if (self.cancleBtnBlock) {
self.cancleBtnBlock();
}
}
#pragma mark - init
- (UITextField *)searchTextFiled
{
if (!_searchTextFiled) {
_searchTextFiled = [[UITextField alloc]init];
_searchTextFiled.backgroundColor = getColor(bgColor);
_searchTextFiled.font = DEF_FontSize_14;
_searchTextFiled.textColor = getColor(textColor);
_searchTextFiled.textAlignment = NSTextAlignmentCenter;
_searchTextFiled.placeholder = @"请输入搜索关键词";
}
return _searchTextFiled;
}
- (UIButton *)cancleBtn
{
if (!_cancleBtn) {
_cancleBtn = [[UIButton alloc]init];
_cancleBtn.backgroundColor = [UIColor clearColor];
[_cancleBtn setTitleColor:getColor(textColor) forState:UIControlStateNormal];
_cancleBtn.titleLabel.font = DEF_FontSize_14;
[_cancleBtn setTitle:@"取消" forState:UIControlStateNormal];
[_cancleBtn addTarget:self action:@selector(cancleBtnAction) forControlEvents:UIControlEventTouchUpInside];
}
return _cancleBtn;
}
@end

自定义收索View的更多相关文章

  1. 自定义控制器的View(loadView)及其注意点

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  2. 贝塞尔曲线:原理、自定义贝塞尔曲线View、使用!!!

    一.原理 转自:http://www.2cto.com/kf/201401/275838.html Android动画学习Demo(3) 沿着贝塞尔曲线移动的Property Animation Pr ...

  3. 20170712 SQL Server 日志文件收索

    -- 1 日志文件增长过快,未进行任务计划截断备份 造成文件过大199G 左右,而可用空间不足8% -- 2 日志备份之前,需要一次完整备份 再进行截断备份 出现可用空间99% 此时可以选择收索数据库 ...

  4. android显示通知栏Notification以及自定义Notification的View

    遇到的最大的问题是监听不到用户清除通知栏的广播.所以是不能监听到的. 自定义通知栏的View,然后service运行时更改notification的信息. /** * Show a notificat ...

  5. 剑指offer-第四章解决面试题思路(二叉收索树和双向链表)

    题目:输入一个二叉收索树,将二叉搜索树转换成排序的双向链表.要求不能创建节点,只能将链表中的指针进行改变. 将复杂的问题简单化:思路:二叉收索树,本身是一个排序结构,中序遍历二叉收索树就可以得到一组排 ...

  6. Android中自定义样式与View的构造函数中的第三个参数defStyle的意义

    零.序 一.自定义Style 二.在XML中为属性声明属性值 1. 在layout中定义属性 2. 设置Style 3. 通过Theme指定 三.在运行时获取属性值 1. View的第三个构造函数的第 ...

  7. Android自定义View4——统计图View

    1.介绍 周末在逛慕课网的时候,看到了一张学习计划报告图,详细记录了自己一周的学习情况,天天都是0节课啊!正好在学习Android自定义View,于是就想着自己去写了一个,这里先给出一张慕课网的图,和 ...

  8. 自定义android RadioButton View,添加较为灵活的布局处理方式

    android的RadioButton的使用历来都让人比较头疼,如在布局方面,图案.文字无法分别设置padding等,另外,低版本的android RadioGroup不支持换行排列的RadioBut ...

  9. 自定义View_1_关于View,ViewGroup的测量和绘制流程

    自定义View(1) ------ 关于View,ViewGroup的测量和绘制流程 在Android当中,自定义控件属于比较高级的知识体系,今天我们就一起研究研究关于自定义View的那点事,看看它到 ...

随机推荐

  1. appium(6)-parts of appium api

    parts of appium api Lock Lock the screen.//锁屏. // java driver.lockScreen(3); // objective c [driver ...

  2. 数据结构之 线性表---单链表操作A (删除链表中的指定元素)

    数据结构上机测试2-1:单链表操作A Time Limit: 1000MS Memory limit: 4096K 题目描述 输入n个整数,先按照数据输入的顺序建立一个带头结点的单链表,再输入一个数据 ...

  3. 浏览器中的BOM和DOM

    BOM 浏览器对象模型 提供了独立于内容而与浏览器窗口进行交互的对象.描述了与浏览器进行交互的方法和接口,可以对浏览器窗口进行访问和操作,譬如可以弹出新的窗口,改变状态栏中的文本,对Cookie的支持 ...

  4. .cxx_destruct crash

    开发过程中遇到 YXTBaseLabelCell .cxx_destruct崩溃,查了下,会在调用类的dealloc方法时调用cxx_destruct,于是看了下代码,找dealloc可能会崩溃的原因 ...

  5. css td 溢出改为省略号

    <style> .table{ table-layout: fixed; width:100%; } .td{ width:100px; white-space: nowrap; over ...

  6. cuda 版本查阅

    查看cuda版本 cat  /usr/local/cuda/version.txt nvcc -V

  7. ubuntu16.04 + cuda9.0(deb版)+Cudnn7.1

    https://blog.csdn.net/Umi_you/article/details/80268983

  8. Linux设备驱动之Kobject、Kset

    作者:lizuobin(也是我们兼职的论坛答疑助手) 原文: https://blog.csdn.net/lizuobin2/article/details/51523693 纠结又纠结,虽然看了一些 ...

  9. 蓝桥杯 2014本科C++ B组 李白打酒 三种实现方法 枚举/递归

    标题:李白打酒 话说大诗人李白,一生好饮.幸好他从不开车. 一天,他提着酒壶,从家里出来,酒壶中有酒2斗.他边走边唱: 无事街上走,提壶去打酒. 逢店加一倍,遇花喝一斗. 这一路上,他一共遇到店5次, ...

  10. ubuntu 禁止错误信息 report 问题弹出

    发现ubuntu只要出现点问题就会提示要不要report error, 光点cancel就点烦了. 而且今天重新安装了一台ubuntu结果开机就蹦出error, 好烦啊. 下面说个特别有效的解决办法, ...