iOS开发-UITextFeild

iOS textField设置placeHold的位置,颜色和输

2016-12-08  本文已影响991人  e40c669177be
//textField占位文字的位置
-(CGRect)placeholderRectForBounds:(CGRect)bounds{
    [super placeholderRectForBounds:bounds];
    CGRect newBounds = bounds;
    newBounds.origin.x = bounds.origin.x + leftOfView;
    
    return newBounds;
    
}

  //textField输入文字的位置 + 光标的位置
  -(CGRect)editingRectForBounds:(CGRect)bounds{
    [super editingRectForBounds:bounds];
    //光标的颜色
//    self.tintColor= [UIColor whiteColor];

    CGRect newBounds = bounds;
    newBounds.origin.x = bounds.origin.x + leftOfView;
    
    return newBounds;
    
 }



//textField输入完成后的位子
- (CGRect)textRectForBounds:(CGRect)bounds{
CGRect newBounds = bounds;
newBounds.origin.x = bounds.origin.x + leftOfView;

return newBounds;


}


  //设置placeHold的颜色+切圆角
   -(void)drawRect:(CGRect)rect{
    
    [self setValue:[UIColor whiteColor] forKeyPath:@"_placeholderLabel.textColor"];
    self.layer.borderWidth = 2;
    self.layer.borderColor = [UIColor whiteColor].CGColor;
    self.layer.cornerRadius = 5;
    self.layer.masksToBounds = YES;

}
上一篇下一篇

猜你喜欢

热点阅读