//
// CCUITextField.m
// CCFC
//
// Created by xichen on 11-12-28.
// Copyright 2011 ccteam. All rights reserved.
//
#import "CCUITextField.h"
@implementation UITextField(cc)
// create a common textField
+ (UITextField *)createCommonTextField:(CGRect)rect
{
UITextField *textField = [[UITextField alloc] initWithFrame:rect];
textField.backgroundColor = [UIColor whiteColor];
return [textField autorelease];
}
// set the clear button status
- (void)addClearButton
{
[self setClearButtonMode:UITextFieldViewModeAlways];
}
// add a leftView
- (UILabel *)addLeftview:(CGRect)leftViewRect text:(NSString *)text
{
UILabel *label = [[UILabel alloc] initWithFrame:leftViewRect];
label.text = text;
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
self.leftViewMode = UITextFieldViewModeAlways;
self.leftView = label;
self.borderStyle = UITextBorderStyleRoundedRect;
[label release];
return label;
}
// add a leftView by a label
- (void)addLeftview:(UILabel *)label
{
label.backgroundColor = [UIColor clearColor];
label.textColor = [UIColor grayColor];
self.leftViewMode = UITextFieldViewModeAlways;
self.leftView = label;
self.borderStyle = UITextBorderStyleRoundedRect;
}
@end
可能有更新:
googlecode链接地址: http://code.google.com/p/iphone-common-codes-ccteam/source/browse/trunk/CCFC/files/CCUITextField.m
github地址: https://github.com/cxsjabc/iphone-common-codes-ccteam/tree/master/CCFC/files/CCUITextField.m
本文介绍了一个自定义UITextField组件的实现方法,包括创建普通文本框、设置清除按钮模式及添加左侧视图等功能。此组件适用于iOS应用开发中对UITextField进行定制化的需求。

被折叠的 条评论
为什么被折叠?



