- (void)viewDidLoad
{
[super viewDidLoad];
//建立在你已經(jīng)遵守了<協(xié)議UITextFieldDelegate>
self.numTF.delegate = self;
self.passTF.delegate = self;
//密文顯示
self.passTF.secureTextEntry = YES;
}
#PRagma mark- UITextField事件監(jiān)聽
//當輸入文本框將要開始編輯時
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
NSLog(@"單行輸入文本框將要開始編輯時");
return YES;
}
//當輸入文本框開始進入編輯模式時
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
NSLog(@"單行輸入文本框開始編輯時");
}
//將要完成編輯時調(diào)用
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField
{
NSLog(@"單行輸入文本框將要完成編輯");
return YES;
}
//已經(jīng)退出編輯模式時
- (void)textFieldDidEndEditing:(UITextField *)textField
{
NSLog(@"已經(jīng)退出編輯模式時調(diào)用");
//打印當前TextField的內(nèi)容
NSLog(@"%@",textField.text);
//顯示到TextLabel
self.textLabel.text = textField.text;
}
//當你按下鍵盤上的Return鍵時調(diào)用該方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
//選中當行輸入文本框時,就改變第一消息響應者的身份。
[self.numTF resignFirstResponder];
[self.passTF resignFirstResponder];
return YES;
}
#pragma mark-字體換行
- (void)viewDidLoad
{
[super viewDidLoad];
//默認自動換行
self.myLabel.numberOfLines = 0;
//顯示的內(nèi)容
NSString *string = @"asdfaeatretgfdsgfdgsdgsdgfsdgsdfgsdfgerwtewrtywetyhwerghgfshw4tygwtrfg";
//顯示的顏色
self.myLabel.backgroundColor = [UIColor redColor];
//顯示出內(nèi)容
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;
}
|
新聞熱點
疑難解答