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

如何限制文本框输入的个数

时间:2015-06-05 10:20:28      阅读:122      评论:0      收藏:0      [点我收藏+]

标签:限制文字个数   文本限制文本个数   ui   

- (void)viewDidLoad {
    [super viewDidLoad];
    UITextField *textF = [[UITextField alloc]initWithFrame:CGRectMake(100, 100, 100, 100)];
    textF.backgroundColor = [UIColor grayColor];
    [self.view addSubview:textF];
    self.textF = textF;
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(limitTextField:) name:@"UITextFieldTextDidChangeNotification" object:textF];


}


- (void)limitTextField:(NSNotification *)note {
    int limit = 5;
    if ([self.textF.text length] > limit) {
        [self.textF setText:[self.textF.text substringToIndex:limit]];
    }
}


-(void)dealloc{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

如何限制文本框输入的个数

标签:限制文字个数   文本限制文本个数   ui   

原文地址:http://blog.csdn.net/u010438187/article/details/46368659

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