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

来源:互联网 发布:奢侈品复刻1:1淘宝 编辑:程序博客网 时间:2024/05/19 03:17


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

    self.searchTF = [[UITextFieldalloc]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 = [UIColorwhiteColor];

    self.searchTF.textColor = [UIColorwhiteColor];

    self.searchTF.delegate =self;

    self.searchTF.backgroundColor =MAIN_THEME_COLOR;

    self.navigationItem.titleView =self.searchTF;

    NSMutableDictionary *attributes = [NSMutableDictionarydictionary];

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

    attributes[NSForegroundColorAttributeName] = [UIColorwhiteColor];

    //设置UITextField的占位文字

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

    //左侧设置放大镜

    self.searchTF.leftViewMode =UITextFieldViewModeAlways;

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

    leftView.image = [UIImageimageNamed:@"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 = [[UIImageViewalloc]initWithFrame:CGRectMake(5, (self.searchTF.bounds.size.height-20)/2,20, 20)];

    leftView.image = [UIImageimageNamed:@"temp_fangdajing"];

    self.searchTF.leftView = leftView;


5.效果




0 0
原创粉丝点击