zoukankan      html  css  js  c++  java
  • iOS---searchBar 搜索框 光标初始位置后移

    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
    +
     
  • 相关阅读:
    javascript 笔记
    i18n,国际化翻译,excel与js互转
    nginx 一个端口布署多个单页应用(history路由模式)。
    html, js,css应用文件路径规则
    vue响应式原理,去掉优化,只看核心
    js 大量数据优化,通用方法
    nginx 常用的location rewrite proxy_pass
    javascript,排列组合
    zk分布式任务管理
    springboot+mybatis+dubbo+aop日志终结篇
  • 原文地址:https://www.cnblogs.com/KiVen2015/p/5822897.html
Copyright © 2011-2022 走看看