具有 UIAlertView 编辑功能的 UILabel 子类。支持掩码密码和占位符。
platform :ios, '7.0'
pod "RFTapEditLabel", "~> 1.2"
RFTapEditLabel 非常易于安装和使用。只需以带有或不带 securTextEntry、带有框架(通常的方式)的方式初始化 RFTapEditLabel
。
RFTapEditLabel *tapLabel = [[RFTapEditLabel alloc] initWithFrame:CGRectMake(20, 100, 180, 31) secureTextEntry:NO];
您可以在 Storyboard 中使用 RFTabEditCell 或 RFTapEditLabel。
要使用 RFTabEditCell,您将 UITableViewCell 自定义类更改为 RFTabEditCell
要使用 RFTapEditLabel,您将 UILabel 自定义类更改为 RFTapEditLabel
您想设置用户定义的运行时属性来控制诸如文字、占位文字以及是否为掩码字等。这些值将在 RFTabEditCell 或 RFTapEditLabel 的 awakeFromNib 中获得
您想要复用具有不同内容的原型单元格,那么从属性文件 plist 中填充字段。
RFTabEditCell 使用以下约束在 UITableView 内部进行对齐
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"|-15-[tapTextLabel]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[tapTextLabel]|" options:0 metrics:nil views:viewsDictionary]];
[self.contentView setNeedsUpdateConstraints];
这就是全部内容,您可以使用以下一些方法。您也可以始终获取任何文本。此外,您还可以初始化 RFTapEditCell
,只需将单元格的 textLabel 设置为自定义标签。
希望您喜欢它!
- (id)initWithFrame:(CGRect)frame secureTextEntry:(BOOL)secureTextEntry;
// standard init, except with an option for a password text field.
- (void)simulateTap;
// tapLabel programatically
- (void)toggleEditable;
// if editable, set uneditable, if uneditable, set editable
- (void)setEditable:(BOOL)editable;
// set editable without toggling
- (void)setLabelTextCustom:(NSString *)labelText;
// use this when setting text AND a placeholder (otherwise unnecessary)
- (void)setPlaceholderText:(NSString *)placeholderText;
// use this for setting a placeholder
- (void)toggleMask;
// toggle mask, show dots or hide them
- (void)toggleMaskForTime:(NSTimeInterval)time;
// toggle mask for time, show dots for x seconds, then hide
- (void)toggleMaskForTime:(NSTimeInterval)time onToggle:(void (^)(void))whileToggled completion:(void (^)(void))completionBlock;
// I have never really used blocks before, and am new to controls, so this works, but may not be implemented properly
// this allows you to set some properties while the label is being toggled, but then you can reset them
- (void)setMaskWithLength:(NSUInteger)maskLength;
// change length of mask for security (by default label sets mask to length of text)
- (NSString*)maskString:(NSUInteger)maskLength;
// return a masked string with the string length (set maskLength) or with a custom maskLength (like setMaskWithLength)
The MIT License (MIT)
版权所有 (c) 2013 Rudd Fawcett
此处免费授予任何人获得本软件及其关联文档文件(“软件”)副本的权利,用于不受限制地处理软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本的权利,并允许向提供软件的个人授予此类权利,但以以下条件为限:
上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。
本软件按照“现状”提供,不提供任何形式的保证,无论明确或暗示,包括但不限于适销性、特定用途的适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任(无论是在合同、侵权或其他行为中)承担责任,无论该索赔、损害或其他责任是否由软件引起、源自或与软件的使用或其他情况有关。