美文网首页iOS开发-UITextFeild
iOS textField设置placeHold的位置,颜色和输

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

作者: e40c669177be | 来源:发表于2016-12-08 16:28 被阅读991次
    //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;
    
    }

    相关文章

      网友评论

        本文标题:iOS textField设置placeHold的位置,颜色和输

        本文链接:https://www.haomeiwen.com/subject/sassmttx.html