• 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
    +
     
  • 相关阅读:
    C 语言定义
    一次系统磁盘异常使用100%的处理
    supervisord 安装、配置体验
    uva 211(dfs)
    poj1651
    有一种感动叫ACM(记WJMZBMR在成都赛区开幕式上的讲话)
    nyoj-746
    Codeforces Round #308 (Div. 2)----C. Vanya and Scales
    long long 与 _int64
    石子归并问题(nyoj737)
  • 原文地址:https://www.cnblogs.com/KiVen2015/p/5822897.html
Copyright © 2020-2023  润新知