ios-UITextField文字内容间距及UITextView的placeHodler设置

****UITextField****

@interface GOVFeedTextField : UITextField

@end
@implementation GOVFeedTextField
// 占位文字与输入框前距离
-(CGRect)textRectForBounds:(CGRect)bounds{
    return  CGRectInset(bounds, LAYOUT_SIZESCALE_PORTRAIT(20, 20).width, 0);
}
// 光标的距离设置
-(CGRect)editingRectForBounds:(CGRect)bounds{
    return  CGRectInset(bounds, LAYOUT_SIZESCALE_PORTRAIT(20, 20).width, 0);
}

@end

在创建的textfield那再调用

[textField textRectForBounds:CGRectMake(5, titleLabel.frame.size.height + titleLabel.frame.origin.y, LAYOUT_SCREENSIZE_P.width - 2 * 15, 39)];
 [textField editingRectForBounds:CGRectMake(5, titleLabel.frame.size.height + titleLabel.frame.origin.y, LAYOUT_SCREENSIZE_P.width - 2 * 15, 39)];

****UITextView的placehodler设置****

 UITextView *suggestView = [[UITextView alloc]initWithFrame:CGRectMake(15, 40, LAYOUT_SCREENSIZE_P.width - 2*15, LAYOUT_SIZESCALE_PORTRAIT(314, 314).height)];
            suggestView.delegate = self;
            suggestView.text = @"我是占位文字";
遵循代理,并实现代理方法
#pragma UITextViewDelegate
- (void)textViewDidBeginEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@"我是占位文字"]) {
        textView.text = @"";
        textView.textColor = [UIColor redColor];
    }
}
-(void)textViewDidEndEditing:(UITextView *)textView{
    if ([textView.text isEqualToString:@""]) {
        textView.text = @"我是占位文字";
        textView.textColor = [UIColor lightGrayColor];
    }
}

你可能感兴趣的:(ios-UITextField文字内容间距及UITextView的placeHodler设置)