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. 原来 Set 集合也可以排序

    Java 集合类主要由两个接口派生而出: Collection 和 Map.在 Collection 集合中,我们经常用到的是 List 集合和 Map 集合,而 Set 集合出场的机会就相对比较的少 ...

  2. lAMP下新建维护站点全过程

    由于window2003年7.15日微软对此不进行更新和支持,因此换了服务器系统由原来的windows2003直接升级到linux,关于LAMP的环境配置请查看我其他的相关博客,在这仅讲述一下LAMP ...

  3. 【 spring配置文件详解】

    转自: http://book.51cto.com/art/201004/193743.htm Spring配置文件是用于指导Spring工厂进行Bean生产.依赖关系注入(装配)及Bean实例分发的 ...

  4. 解决Android Studio Fetching Android SDK component information失败问题【转】

    本文转载自:http://blog.csdn.net/isesar/article/details/41908089 Android Studio 安装完成后,如果直接启动,Android Studi ...

  5. Codeforces Round #394 (Div. 2) C. Dasha and Password —— 枚举

    题目链接:http://codeforces.com/problemset/problem/761/C C. Dasha and Password time limit per test 2 seco ...

  6. python字典无序?有序?

    默认情况下Python的字典输出顺序是按照键的创建顺序. 字典的无序是指,不能人为重新排序.比如说你按键值1,2,3,4的顺序创建的字典,只能由解析器按创建顺序,还是1,2,3,4的输出.你无法控制它 ...

  7. the art of seo(chapter five)

    Keyword Research ***The Theory Behind Keyword Research***1.When users go to search engines and type ...

  8. Asterisk func group

    Synopsis Gets, sets or clears the channel group. Each channel can only be member of exactly one grou ...

  9. QQ登陆功能的实现2

    QQ登陆功能的实现2 由于看到园子里有朋友说需要讲解和剖析实现的步骤,前面的QQ登陆实现只有代码,所以这篇补上 1.  分析 1). 当运行QQ.exe后会出现qq登陆界面的窗体 2). 我们用spy ...

  10. NHibernate从入门到精通系列——NHibernate环境与结构体系

    内容摘要 NHibernate的开发环境 NHibernate的结构体系 NHibernate的配置 一.NHibernate的开发环境 NHibernate的英文官方网站为:http://nhfor ...