首页 技术 正文
技术 2022年11月15日
0 收藏 912 点赞 3,043 浏览 1347 个字
  1. #import <UIKit/UIKit.h>
  2. @interface SearchBar : UITextField
  3. @property (nonatomic,strong) UIButton *button;
  4. + (instancetype)searchBar;
  5. @end
  6. #import "SearchBar.h"
  7. @implementation SearchBar
  8. - (id)initWithFrame:(CGRect)frame
  9. {
  10. self = [super initWithFrame:frame];
  11. if (self) {
  12. self.font = [UIFont systemFontOfSize:15];
  13. self.placeholder = @" 输入品种关键字";
  14. //设置边框和边框颜色
  15. self.borderStyle=UITextBorderStyleNone;
  16. self.layer.cornerRadius=15.0f;
  17. self.layer.masksToBounds=YES;
  18. self.layer.borderColor=[[UIColor colorWithRed:224/255.0 green:243/255.0 blue:223/255.0 alpha:1.0]CGColor];
  19. self.layer.borderWidth= 2.0f;
  20. UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 40, 30)];
  21. [button setBackgroundImage:[UIImage imageNamed:@"seachBar_rightView"] forState:UIControlStateNormal];
  22. [button setTitle:@"搜索" forState:UIControlStateNormal];
  23. [button setTitleColor:[UIColor colorWithRed:119/255.0 green:166/255.0 blue:16/255.0 alpha:1.0] forState:UIControlStateNormal];
  24. button.titleLabel.font = [UIFont systemFontOfSize:18.0];
  25. button.titleLabel.textColor = [UIColor colorWithRed:119/255.0 green:166/255.0 blue:16/255.0 alpha:1.0];
  26. button.titleLabel.textColor = [UIColor redColor];
  27. self.rightView = button;
  28. self.rightViewMode = UITextFieldViewModeAlways;
  29. //这里设置光标位置,让光标位置后移10
  30. self.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 0)];
  31. self.leftViewMode = UITextFieldViewModeAlways;
  32. }
  33. return self;
  34. }
  35. + (instancetype)searchBar
  36. {
  37. return [[self alloc] init];
  38. }
  39. @end

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,111
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,203
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,838
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,922