attribute:borderStyle,background,disabledBackground,font,text,enabled,textAligment,placeholder(输入框提示信息),clearButtonMode(文本框清除按钮出现时间)
UITextField *myText = [[UITextField alloc] initWithFrame:]
//键盘退出
[myText resignFirstResponder]
//设置富文本内容
//给富文本添加各种属性
NSMutableAttributedString *attrubutedString = [[NSMutableAttributedString alloc] initWithString:@"hello world"];
//设置字体颜色
[attrubutedString addAttribute:NSForegroundColorAttributeName value:[UIColor yellowColor] range:[attrubutedString.string rangeOfString:@"world"]];
//设置字体粗体,字号
[attrubutedString addAttribute:NSFontAttributeName value:[UIFont boldSystemFontOfSize:15] range:[attrubutedString.string rangeOfString:@"world"]];
//批量设置富文本效果
//[attrubutedString addAttributes:<#(NSDictionary *)#> range:<#(NSRange)#>]
myText.attributedText = attrubutedString;
//在UITextField中添加图片,左右不能同时存在图片
UIImageView *left = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"01"]];
myText.leftView = left;//图片位置
myText.leftViewMode = UITextFieldViewModeUnlessEditing;//图片出现时间
//让myText文本对象支持UITextFieldDelegate协议
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField;
- (void)textFieldDidBeginEditing:(UITextField *)textField;
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField;//限制用户输入字数时能用到
- (void)textFieldDidEndEditing:(UITextField *)textField;
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
- (BOOL)textFieldShouldClear:(UITextField *)textField;
- (BOOL)textFieldShouldReturn:(UITextField *)textField;
myText.delegate = self;
//弹出的键盘
inputView属性
//设置键盘上方的小条
accessView属性
//改变return键的作用
myText.returnKeyType = UIReturnKeyYahoo;
//改变键盘类型
//myText.keyboardType = UIKeyboardTypePhonePad;
//界面跳转模式:模态跳转
//点击按钮跳转界面
-(void)onClick:(UIButton *)btn
{
//对象
CATransition *trans = [CATransition animation];
//属性
[trans setDuration:3];
//动画类型
//cube pageCurl pageUnCurl rippleEffect rippleEffect oglFlip
//[trans setType:@"oglFlip"];
[trans setType:kCATransitionMoveIn];
//子动画类型
[trans setSubtype:kCATransitionFromRight];
//给图层添加动画
[self.view.window.layer addAnimation:trans forKey:nil];
//创建第二个界面
SecondViewController *svc = [[SecondViewController alloc] init];
svc.content = tf.text;//content是在SecondViewController中定义
//跳转到第二个界面
[self presentViewController:svc animated:NO completion:nil];
}
//返回第一个界面
[self dismissViewControllerAnimated:YES completion:nil];
单例模式:某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例。这个类称为单例类