UITextField文本字段控件的位置
2016-07-08 11:48
483 查看
如果需要更改默认的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; }
相关文章推荐
- WRONGTYPE Operation against a key holding the wrong kind of value
- UITextField占位文字颜色-attributedPlaceholder
- Java并发编程与技术内幕:ArrayBlockingQueue、LinkedBlockingQueue及SynchronousQueue源码解析
- Process 'command '/Users/wcc/Android/sdk/build-tools/23.0.0/aidl'' finished with non-zero exit valu
- CUICatalog: Invalid asset name supplied:
- Android Bluetooth Low Energy官方文档翻译
- abap 弹出对话框函数POPUP_GET_VALUES的使用方法
- 如何监控项目里所有UI线程的操作(实战,BlockCanary)?
- UITextView的placehoder背景文字实现带并限制文字字数
- UICollectionReusableView 使用时的一些问题
- @value注解使用的简单介绍 ---谷营中西
- 数据类型变换uint8_t uint16_t等等
- Android 在子线程中更新UI的方式,使用handler
- Warning:The remote SSH server rejected X11 forwarding request.
- UICollectionViewLayout
- Errors running builder 'Validation' on project 'jumi_3.0'
- 点击tabBarItem跳转到其他界面 返回后还是之前所选item (跳转注册)
- php中生成标准uuid(guid)的方法
- error: static assertion failed: (boost::has_trivial_destructor<T>::value)
- non-zero exit value 1,non-zero exit value 2, non-zero exit value 3错误解决办法