新浪微博之自定义搜索框
来源:互联网 发布:sql 查询重复记录 编辑:程序博客网 时间:2024/05/17 08:28
搜索框继承于UITextField
@interface WZSearchBar : UITextField
@end
注意:一个拉伸不变形的问题。
+(instancetype)resizeableImageWithName:(NSString *)imageName
{
UIImage *image = [UIImageimageWithName:imageName];
CGFloat left = image.size.width *0.5;
CGFloat top = image.size.height *0.5;
//实现拉伸不变形
image = [imagestretchableImageWithLeftCapWidth:lefttopCapHeight:top];
return image;
}
@implementation WZSearchBar
- (instancetype)initWithFrame:(CGRect)frame
{
self = [superinitWithFrame:frame];
if (self)
{
//设置背景图片
self.background = [UIImageresizeableImageWithName:@"searchbar_textfield_background"];
//设置文本垂直居中
self.contentVerticalAlignment =UIControlContentVerticalAlignmentCenter;
//设置清除按钮
self.clearButtonMode =UITextFieldViewModeWhileEditing;
//添加放大镜到搜索框上
UIImageView *iv = [[UIImageViewalloc] initWithImage:[UIImageimageWithName:@"searchbar_textfield_search_icon"]];
self.leftView = iv;
self.leftViewMode =UITextFieldViewModeAlways;
CGRect frame = iv.frame;
frame.size.width =40;
iv.frame = frame;
iv.contentMode =UIViewContentModeCenter;
//设置默认提示问题
self.placeholder =@"亲,请输入要搜索的内容~";
self.frame =CGRectMake(0,0, 300,35);
}
returnself;
}
@end
另外要注意的一个问题:
WZSearchBar *searchBar = [[WZSearchBaralloc] init];
searchBar.placeholder =@"亲~请输入要搜索的内容~";
//注意:如果控件是添加到导航条上作为导航条的titleView,设置Frame的x,y无效
searchBar.frame =CGRectMake(0,0, 300,35);
self.navigationItem.titleView = searchBar;
- 新浪微博之自定义搜索框
- 新浪微博开发-(6)自定义搜索框
- ios-新浪微博开发07-自定义搜索框
- 新浪微博开发六(自定义搜索条)
- 【通知】新浪微博搜索
- 自定义UITableViewCell新浪微博
- 新浪微博搜索:下一站天王?
- 新浪微博搜索结果数据抓取
- 【分享】邓文迪新浪微博搜索结果
- 新浪微博关键字搜索结果抓取
- 新浪微博简单搜索接口
- Qt之自定义搜索框
- Qt之自定义搜索框
- Qt之自定义搜索框
- Android之自定义搜索框
- qt 之自定义 搜索框
- 新浪微博数据挖掘食谱之三: 搜索篇 (selenium)
- 新浪微博如何自定义来源尾巴
- 南宁大便带血前期是什么
- HDU 2546 饭卡
- Vim插件使用之 AutoComplPop---自动补全
- 软件测试- 测试用例之等价类划分法
- html之表单
- 新浪微博之自定义搜索框
- 南宁什么药治混合痔最好
- PAT Maximum Subsequence Sum (25)
- CodeForces - 548C Mike and Frog(扩展欧几里德)
- 南宁专治混合痔线上医生
- 【Android UI设计与开发】第01期:引导界面(一)ViewPager介绍和使用详解
- 南宁混合痔的危害有哪些
- 有关 Python 2 和 Sublime Text 中文 Unicode 编码问题的分析与理解
- 南宁割混合痔需要多久好