欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

IOS笔记之UIKit_UITextField,uikit_uitextfield

来源: 开发者 投稿于  被查看 35771 次 评论:3

IOS笔记之UIKit_UITextField,uikit_uitextfield


- (void)viewDidLoad

{

    [super viewDidLoad];

    //建立在你已经遵守了<协议UITextFieldDelegate>

    self.numTF.delegate  = self;

    self.passTF.delegate = self;

    //密文显示

    self.passTF.secureTextEntry = YES;

}

 

#pragma mark- UITextField事件监听

//当输入文本框将要开始编辑时

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField

{

    NSLog(@"单行输入文本框将要开始编辑时");

    return YES;

}

 

//当输入文本框开始进入编辑模式时

- (void)textFieldDidBeginEditing:(UITextField *)textField

{

    NSLog(@"单行输入文本框开始编辑时");

}

 

//将要完成编辑时调用

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField

{

    NSLog(@"单行输入文本框将要完成编辑");

    return YES;

}

//已经退出编辑模式时

- (void)textFieldDidEndEditing:(UITextField *)textField

{

    NSLog(@"已经退出编辑模式时调用");

    //打印当前TextField的内容

    NSLog(@"%@",textField.text);

    //显示到TextLabel

    self.textLabel.text = textField.text;

}

 

//当你按下键盘上的Return键时调用该方法

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    //选中当行输入文本框时,就改变第一消息响应者的身份。

    [self.numTF resignFirstResponder];

    [self.passTF resignFirstResponder];

    return YES;

}

 

#pragma mark-字体换行

- (void)viewDidLoad

{

    [super viewDidLoad];

//默认自动换行

    self.myLabel.numberOfLines = 0;

//显示的内容

    NSString *string = @"asdfaeatretgfdsgfdgsdgsdgfsdgsdfgsdfgerwtewrtywetyhwerghgfshw4tygwtrfg";

//显示的颜色 

  self.myLabel.backgroundColor = [UIColor redColor];

//显示出内容

    self.myLabel.text = string;

    //计算文本高度(字典)

    NSDictionary *attribute = @{NSFontAttributeName: self.myLabel.font};

    CGSize size = [string boundingRectWithSize:CGSizeMake(100, 0) options: NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attribute context:nil].size;

    

    CGRect frame = self.myLabel.frame;

    frame.size.height = size.height;

    self.myLabel.frame = frame;

}

用户评论