簡(jiǎn)單設(shè)置placeHolder字體的大小大小 顏色
NSString*placeholderString =@"搜一搜";
NSMutableAttributedString*placeholder = [[NSMutableAttributedStringalloc]initWithString:placeholderString];
[placeholderaddAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:14]range:NSMakeRange(0, placeholderString.length)];
[placeholderaddAttribute:NSForegroundColorAttributeNamevalue:[UIColoryellowColor]range:NSMakeRange(0,placeholderString.length)];
self.searchTextField.attributedPlaceholder= placeholder;
要對(duì)UItextField 的光標(biāo) leftView 以及顯示文本 位置 要重寫
- (CGRect)borderRectForBounds:(CGRect)bounds;
- (CGRect)textRectForBounds:(CGRect)bounds;
- (CGRect)placeholderRectForBounds:(CGRect)bounds;
- (CGRect)editingRectForBounds:(CGRect)bounds;
- (CGRect)clearButtonRectForBounds:(CGRect)bounds;
- (CGRect)leftViewRectForBounds:(CGRect)bounds;
- (CGRect)rightViewRectForBounds:(CGRect)bounds;
//控制清除按鈕的位置
-(CGRect)clearButtonRectForBounds:(CGRect)bounds
{
returnCGRectMake(bounds.origin.x+ bounds.size.width-50, bounds.origin.y+ bounds.size.height-20,16,16);
}
//控制placeHolder的位置,左右縮20
-(CGRect)placeholderRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds, 20, 0);
CGRectinset =CGRectMake(bounds.origin.x+35, bounds.origin.y+2, bounds.size.width-10, bounds.size.height);//更好理解些
returninset;
}
//控制顯示文本的位置
-(CGRect)textRectForBounds:(CGRect)bounds
{
//return CGRectInset(bounds, 50, 0);
CGRectinset =CGRectMake(bounds.origin.x+35, bounds.origin.y, bounds.size.width-10, bounds.size.height);//更好理解些
returninset;
}
//控制編輯文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds
{
//return CGRectInset( bounds, 10 , 0 );
CGRectinset =CGRectMake(bounds.origin.x+35, bounds.origin.y, bounds.size.width-10, bounds.size.height);
returninset;
}
//控制左視圖位置
- (CGRect)leftViewRectForBounds:(CGRect)bounds
{
CGRectinset =CGRectMake(bounds.origin.x+15, bounds.origin.y+9,15,13);
returninset;
//return CGRectInset(bounds,50,0);
}