iOS UITextField 设置内边距
2015-06-19 16:39
513 查看
http://blog.csdn.net/erica_sadun/article/details/9088181
1.inherit UITextField Class.
[cpp] view plaincopy
.h
//
// TextField.h
// TTShow
//
// Created by twb on 13-9-10.
// Copyright (c) 2013年 twb. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TextField : UITextField
@property (nonatomic, assign) CGFloat dx;
@property (nonatomic, assign) CGFloat dy;
@end
[cpp] view plaincopy
.m
//
// TextField.m
// TTShow
//
// Created by twb on 13-9-10.
// Copyright (c) 2013年 twb. All rights reserved.
//
#import "TextField.h"
#define kTextFieldPaddingWidth (10.0f)
#define kTextFieldPaddingHeight (10.0f)
@implementation TextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (CGRect)textRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds,
self.dx == 0.0f ? kTextFieldPaddingWidth : self.dx,
self.dy == 0.0f ? kTextFieldPaddingHeight : self.dy);
}
- (CGRect)editingRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds,
self.dx == 0.0f ? kTextFieldPaddingWidth : self.dx,
self.dy == 0.0f ? kTextFieldPaddingHeight : self.dy);
}
- (void)setDx:(CGFloat)dx
{
_dx = dx;
[self setNeedsDisplay];
}
- (void)setDy:(CGFloat)dy
{
_dy = dy;
[self setNeedsDisplay];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
2.APPLE private method.
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingTop"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingLeft"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingBottom"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingRight"];
1.inherit UITextField Class.
[cpp] view plaincopy
.h
//
// TextField.h
// TTShow
//
// Created by twb on 13-9-10.
// Copyright (c) 2013年 twb. All rights reserved.
//
#import <UIKit/UIKit.h>
@interface TextField : UITextField
@property (nonatomic, assign) CGFloat dx;
@property (nonatomic, assign) CGFloat dy;
@end
[cpp] view plaincopy
.m
//
// TextField.m
// TTShow
//
// Created by twb on 13-9-10.
// Copyright (c) 2013年 twb. All rights reserved.
//
#import "TextField.h"
#define kTextFieldPaddingWidth (10.0f)
#define kTextFieldPaddingHeight (10.0f)
@implementation TextField
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
}
return self;
}
- (CGRect)textRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds,
self.dx == 0.0f ? kTextFieldPaddingWidth : self.dx,
self.dy == 0.0f ? kTextFieldPaddingHeight : self.dy);
}
- (CGRect)editingRectForBounds:(CGRect)bounds
{
return CGRectInset(bounds,
self.dx == 0.0f ? kTextFieldPaddingWidth : self.dx,
self.dy == 0.0f ? kTextFieldPaddingHeight : self.dy);
}
- (void)setDx:(CGFloat)dx
{
_dx = dx;
[self setNeedsDisplay];
}
- (void)setDy:(CGFloat)dy
{
_dy = dy;
[self setNeedsDisplay];
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
@end
2.APPLE private method.
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingTop"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingLeft"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingBottom"];
[self.yourTextField setValue:[NSNumber numberWithInt:5] forKey:@"_paddingRight"];
相关文章推荐
- GPUImge
- cPickle.load(f) ValueError: insecure string pickle错误问题
- GUI_Download的Codepage参数
- uva 1151 - Buy or Build poj 2784 Buy or Build(最小生成树)
- uwsgi invalid request block size: 的解决办法
- cannot set options after executing query
- UIView常用的一些方法小记之setNeedsDisplay和setNeedsLayout
- 压缩UI深度的代码实现
- ABP 初探 之基于EasyUI的CURD
- iOS开发UI篇—CAlayer层的属性
- Uva - 12166 - Equilibrium Mobile
- IOS UITableViewCell 分割左对齐处理
- Uva - 12166 - Equilibrium Mobile
- 自定义Activity标题栏(Title bar)和窗体显示状态操作(requestWindowFeature()的应用)
- Android安装应用失败UID 和 PID
- HTML Dom querySelector
- MonkyTalk学习-5-TestSuite
- moqui框架介绍
- 传智播客网页平面UI入驻武汉校区
- WebUI-自用