IOS 学习UItextFile常用设置
来源:互联网 发布:js实现图片90度旋转 编辑:程序博客网 时间:2024/05/17 07:10
- @implementation AppDelegate
- {
- UITextField *_field;
- UIButton *button;
- }
- - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
- {
- self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
- // Override point for customization after application launch.
- UITextField *textField = [[UITextField alloc]init];
- textField.frame = CGRectMake(10, 30, 300, 30);
- // UITextBorderStyleNone,
- // UITextBorderStyleLine, // 黑色线条框,内部颜色不是透明的
- // UITextBorderStyleBezel, // 灰色的框,内部也是透明的
- // UITextBorderStyleRoundedRect 圆角输入框,内部颜色白色
- textField.borderStyle = UITextBorderStyleRoundedRect;
- //textField.backgroundColor = [UIColor redColor];
- // 文字提示
- textField.placeholder = @"请输入密码";
- textField.secureTextEntry = YES;
- // UIKeyboardTypeDefault,
- // UIKeyboardTypeASCIICapable,
- // UIKeyboardTypeNumbersAndPunctuation,
- // UIKeyboardTypeURL,
- // UIKeyboardTypeNumberPad,
- // UIKeyboardTypePhonePad,
- // UIKeyboardTypeNamePhonePad,
- // UIKeyboardTypeEmailAddress,
- // UIKeyboardTypeDecimalPad NS_ENUM_AVAILABLE_IOS(4_1),
- // UIKeyboardTypeTwitter NS_ENUM_AVAILABLE_IOS(5_0),
- // UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
- // 设置键盘样式
- textField.keyboardType = UIKeyboardTypeASCIICapable;
- // UIKeyboardAppearanceDefault,
- // UIKeyboardAppearanceDark
- // UIKeyboardAppearanceLight
- // UIKeyboardAppearanceAlert = UIKeyboardAppearanceDark, // Deprecated
- // 设置键盘风格
- textField.keyboardAppearance = UIKeyboardAppearanceAlert;
- // 设置弹出视图
- UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"image/backrground.png"]];
- image.frame = CGRectMake(0, 100, 320, 100);
- // 再次编辑时是否清空之前的内容
- textField.clearsOnBeginEditing = YES;
- // 自己订阅键盘的样式
- textField.inputView = image;
- // 设置左视图
- UIView *leftView = [[UIView alloc]init];
- leftView.frame = CGRectMake(0, 0, 100, 100);
- leftView.backgroundColor = [UIColor orangeColor];
- textField.leftView = leftView;
- // UITextFieldViewModeNever,
- // UITextFieldViewModeWhileEditing,
- // UITextFieldViewModeUnlessEditing,
- // UITextFieldViewModeAlways
- textField.leftViewMode = UITextFieldViewModeAlways;
- UIView *rightView = [[UIView alloc]init];
- rightView.frame = CGRectMake(0, 0, 100, 100);
- rightView.backgroundColor = [UIColor greenColor];
- //textField.rightView = rightView;
- textField.rightViewMode = UITextFieldViewModeAlways;
- // 设置清除按钮模式
- textField.clearButtonMode = UITextFieldViewModeAlways;
- // 是否设置清空之前输入的内容
- textField.clearsOnBeginEditing = YES;
- [self.window addSubview:textField];
- [image release];
- [textField release];
- _field = [[UITextField alloc]init];
- _field.frame = CGRectMake(10, 150, 300, 30);
- _field.borderStyle = UITextBorderStyleRoundedRect;
- // 再次输入清空之前的内容
- _field.clearsOnBeginEditing = YES;
- // UIControlContentHorizontalAlignmentCenter = 0,
- // UIControlContentHorizontalAlignmentLeft = 1,
- // UIControlContentHorizontalAlignmentRight = 2,
- // UIControlContentHorizontalAlignmentFill = 3,
- // 横向纵齐
- _field.contentHorizontalAlignment = UIControlContentHorizontalAlignmentFill;
- // 垂直对齐方式
- _field.contentVerticalAlignment = UIControlContentHorizontalAlignmentFill;
- // 文本对齐方式
- _field.textAlignment = NSTextAlignmentCenter;
- // 设置textField滚动
- _field.adjustsFontSizeToFitWidth = YES;
- // 设置最小字号
- _field.minimumFontSize = 50;
- // 设置首字母是否大写
- // UITextAutocapitalizationTypeNone,
- // UITextAutocapitalizationTypeWords, 每一个字母首字目大写
- // UITextAutocapitalizationTypeSentences, 一行句子的首字母单词大写
- // UITextAutocapitalizationTypeAllCharacters, // 所有单词都大写
- _field.autocapitalizationType = UITextAutocapitalizationTypeSentences;
- // 自动纠正
- _field.autocorrectionType = UITextAutocorrectionTypeYes;
- // 设置return 键样式
- _field.returnKeyType = UIReturnKeyRoute;
- // 设置代理
- _field.delegate =self;
- _field.clearButtonMode = UITextFieldViewModeUnlessEditing;
- _field.clearButtonMode = UITextFieldViewModeAlways;
- // UIControl *control = [[UIControl alloc]init];
- // control.frame = CGRectMake(0, 0, 320, 30);
- // [control addTarget:self action:@selector(controlClick) forControlEvents:UIControlEventTouchUpInside];
- [self.window addSubview:_field];
- // [self.window addSubview:control];
- // [self.window sendSubviewToBack:control];
- // [control release];
- button = [UIButton buttonWithType:UIButtonTypeSystem];
- button.frame = CGRectMake(10, 400, 300, 30);
- button.backgroundColor = [UIColor whiteColor];
- [button addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
- [button setTitle:@"登陆" forState:UIControlStateNormal];
- self.window.backgroundColor = [UIColor blueColor]; // 影响的是输入框内部的颜色
- // 订阅键盘升起的系统通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow) name:UIKeyboardWillShowNotification object:nil];
- // 订阅键盘收起的系统通知
- [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardwillHide) name:UIKeyboardWillHideNotification object:nil];
- [self.window addSubview:button];
- [self.window makeKeyAndVisible];
- return YES;
- }
- - (void)dealloc
- {
- [button dealloc];
- [_field dealloc];
- [super dealloc];
- }
- - (void)keyboardWillShow
- {
- [UIView animateWithDuration:0.25 animations:^{
- button.frame = CGRectMake(10, 220, 300, 30);
- }completion:^(BOOL finished) {
- }];
- }
- - (void)keyboardwillHide
- {
- [UIView animateWithDuration:0.25 animations:^{
- button.frame = CGRectMake(10, 400, 300, 30);
- }completion:^(BOOL finished) {
- }];
- }
- - (void)btnClick
- { // 方法 2
- [_field resignFirstResponder]; // 一点击就退出键盘(control控制键盘)
- }
- - (void)controlClick
- { // 方法 2
- [_field resignFirstResponder]; // 一点击就退出键盘(control控制键盘)
- }
- - (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
- { // 是否应该进入编辑模式
- return YES;
- }
- - (BOOL)textFieldShouldEndEditing:(UITextField *)textField
- { // 将进入编辑模式
- return YES;
- }
- - (BOOL)textFieldShouldReturn:(UITextField *)textField
- { // 点击return收起键盘(方法 1)
- [textField resignFirstResponder]; // 收键盘
- return YES;
- }
- - (void)textFieldDidEndEditing:(UITextField *)textField
- { // 进入编辑模式
- NSLog(@"进入编辑模式是调用");
- }
- //- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string;
- // return NO to not change text
- //
- - (BOOL)textFieldShouldClear:(UITextField *)textField
- {
- textField.text = @""; // 手动清除
- return NO;
- }
- // called when clear button pressed. return NO to ignore (no notifications)
- //- (BOOL)textFieldShouldReturn:(UITextField *)textField;
- // called when 'return' key pressed. return NO to ignore.
- - (void)applicationWillResignActive:(UIApplication *)application
- {
- // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- }
- - (void)applicationDidEnterBackground:(UIApplication *)application
- {
- // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- }
- - (void)applicationWillEnterForeground:(UIApplication *)application
- {
- // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- }
- - (void)applicationDidBecomeActive:(UIApplication *)application
- {
- // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- }
- - (void)applicationWillTerminate:(UIApplication *)application
- {
- // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
- }
0 0
- IOS 学习UItextFile常用设置
- UITextFile 的常用设置
- UItextFile常用操作设置
- iOS UITextfile详解
- IOS-UITextFile最全总结
- IOS-UITextFile最全总结
- iOS 学习日志:infoplist常用设置
- 导航栏背景及UItextFile左右图片的设置
- iOS开发UItextfile弹出日期选择控制器输入日期
- ios学习笔记——UITextField常用属性及设置
- iOS UIButton 常用设置
- ios 常用放法、设置
- iOS UITextField常用的设置
- ios学习常用网站
- 学习ios常用网站
- UITextFile UITextView 键盘回收
- IOS常用控件及编译器设置
- iOS开发之UITextField常用属性设置
- Python 中配置文件处理详解--ConfigParser,有了它就可随意操作配置文件了
- ios 监听app从后台恢复到前台
- gluBuild2DMipmaps()与glTexImage2D()的使用方法及区别
- 邮箱校验(js)
- 空指针漏洞防护技术-初级篇
- IOS 学习UItextFile常用设置
- 递归搜索法反汇编
- eclipse中向svn提交代码冲突的解决
- jQuery 实现图片滚动加载()
- 锋利的JQuery 学习笔记
- epoll详解
- 服务器HTTP长连接与短连接
- Openjudge4980 拯救行动(bfs)
- Quatz Job Scheduler初探示例