码迷,mamicode.com
首页 > 其他好文 > 详细

UITextField文本字段控件的位置

时间:2016-07-08 13:27:38      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

 

如果需要更改默认的UITextField清除按钮、左右视图等等控件的位置,可以通过如下设置:

// 控制清除按钮的位置 (默认 width = 15 = height)
-(CGRect)clearButtonRectForBounds:(CGRect)bounds {
//    NSLog(@"=%f ,=%f",bounds.origin.y,bounds.size.height/2);
    return CGRectMake(bounds.origin.x + bounds.size.width - 50, (bounds.size.height - 15)/2, 15, 15);
}

// 控制placeHolder的位置 默认(0,0,width,height)
-(CGRect)placeholderRectForBounds:(CGRect)bounds {
    
//    return CGRectInset(bounds, 20, 0);
    CGRect inset = CGRectMake(bounds.origin.x + 50, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
}

// 控制显示文本的位置  默认(0,0,width,height)
-(CGRect)textRectForBounds:(CGRect)bounds {
    
    NSLog(@"显示文本==%@",NSStringFromCGRect(bounds));
    //return CGRectInset(bounds, 50, 0);
    CGRect inset = CGRectMake(bounds.origin.x + 190, bounds.origin.y, bounds.size.width - 10, bounds.size.height);
    return inset;
    
}

// 控制编辑文本的位置
-(CGRect)editingRectForBounds:(CGRect)bounds {
    
    NSLog(@"编辑文本==%@",NSStringFromCGRect(bounds));
    //return CGRectInset( bounds, 10 , 0 );
    CGRect inset = CGRectMake(bounds.origin.x + 100, bounds.origin.y, bounds.size.width -10, bounds.size.height);
    return inset;
}

// 控制左视图位置 (默认 width=30)
- (CGRect)leftViewRectForBounds:(CGRect)bounds {
    
    NSLog(@"左视图位置==%@",NSStringFromCGRect(bounds));
    
    CGRect inset = CGRectMake(bounds.origin.x + 2, bounds.origin.y, 30, bounds.size.height);
    return inset;
    //return CGRectInset(bounds,50,0);
}

// 控制placeHolder的颜色、字体
- (void)drawPlaceholderInRect:(CGRect)rect {
    
    [[self placeholder] drawInRect:rect withAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.0f],
                                                         NSForegroundColorAttributeName:[UIColor darkGrayColor]
                                                         }];
    
}


// 右视图的位置 (默认整个 width)
- (CGRect)rightViewRectForBounds:(CGRect)bounds {
    
    NSLog(@"右视图位置==%@",NSStringFromCGRect(bounds));
    
    CGRect inset = CGRectMake(bounds.size.width - 30, bounds.origin.y, 30, bounds.size.height);
    return inset;
}

 

UITextField文本字段控件的位置

标签:

原文地址:http://www.cnblogs.com/Mr-Ygs/p/5652920.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!