在导航栏上添加控件和UITextField改变光标颜色和改变站位符颜色


1.在导航栏添加一个UITextField代码:

    self.searchTF = [[UITextField alloc]initWithFrame:CGRectMake(50, 0, SCREEN_SIZE_WIDTH-100, 35)];

    self.searchTF.font = MIDDLE_FONT;

    self.searchTF.layer.cornerRadius = BUTTON_RADUIS;

    self.searchTF.placeholder = @"化妆品";

    self.searchTF.tintColor = [UIColor whiteColor];

    self.searchTF.textColor = [UIColor whiteColor];

    self.searchTF.delegate = self;

    self.searchTF.backgroundColor = MAIN_THEME_COLOR;

    self.navigationItem.titleView = self.searchTF;

    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

    // 设置富文本对象的颜色

    attributes[NSForegroundColorAttributeName] = [UIColor whiteColor];

    // 设置UITextField的占位文字

    self.searchTF.attributedPlaceholder = [[NSAttributedString alloc] initWithString:@"手机号" attributes:attributes];

    //左侧设置放大镜

    self.searchTF.leftViewMode = UITextFieldViewModeAlways;

    UIImageView *leftView = [[UIImageView alloc]initWithFrame:CGRectMake(5, (self.searchTF.bounds.size.height-20)/2, 20, 20)];

    leftView.image = [UIImage imageNamed:@"temp_fangdajing"];

    self.searchTF.leftView = leftView;


2.改变光标颜色

    self.searchTF.tintColor = [UIColor whiteColor];


3.改变占位符颜色

    NSMutableDictionary *attributes = [NSMutableDictionary dictionary];

    // 设置富文本对象的颜色

    attributes[NSForegroundColorAttributeName] = [UIColor whiteColor];

    // 设置UITextField的占位文字

    self.searchTF.attributedPlaceholder = [[NSAttributedString allocinitWithString:@"手机号" attributes:attributes];


4.设置左侧的站位图放大镜

    //左侧设置放大镜

    self.searchTF.leftViewMode = UITextFieldViewModeAlways;

    UIImageView *leftView = [[UIImageView alloc]initWithFrame:CGRectMake(5, (self.searchTF.bounds.size.height-20)/2, 20, 20)];

    leftView.image = [UIImage imageNamed:@"temp_fangdajing"];

    self.searchTF.leftView = leftView;


5.效果




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值