UITextField
2015-09-21 14:45
351 查看
AppDelegate.h
AppDelegate.m
#import <UIKit/UIKit.h> @interface AppDelegate : UIResponder <UIApplicationDelegate> @property (strong, nonatomic) UIWindow *window; @end
AppDelegate.m
#import "AppDelegate.h" @interface AppDelegate () @property(nonatomic, retain)UITextField *secondText; @property(nonatomic, retain)UITextField *textField; @end @implementation AppDelegate - (void)dealloc { [_window release]; [_secondText release]; [_textField release]; [super dealloc]; } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; // Override point for customization after application launch. self.window.backgroundColor = [UIColor whiteColor]; [self.window makeKeyAndVisible]; [_window release]; self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 150, 50)]; self.textField.backgroundColor = [UIColor yellowColor]; [self.window addSubview:self.textField]; [self.textField release]; // 边框 self.textField.layer.borderWidth = 1; // 弧度 self.textField.layer.cornerRadius = 10; // textField.text = @"hehehe和"; self.textField.textColor = [UIColor redColor]; self.textField.textAlignment = NSTextAlignmentCenter; self.textField.font = [UIFont systemFontOfSize:21]; // [textField sizeToFit]; // textField.center = CGPointMake(100, 100); self.textField.placeholder = @"请输入内容"; // 控制能否使用输入框 self.textField.enabled = YES; // 密码效果 self.textField.secureTextEntry = NO; // 键盘类型 // textField.keyboardType = UIKeyboardTypeNumberPad; // 改变return按钮的样式 self.textField.returnKeyType = UIReturnKeyYahoo; UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)]; view.backgroundColor = [UIColor yellowColor]; // 可以通过自定义的视图, 取代键盘 // textField.inputView = view; // textField.inputAccessoryView = view; // 清除按钮 self.textField.clearButtonMode = UITextFieldViewModeAlways; // 给textFlield添加一个事件 [self.textField addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventEditingChanged]; [_textField release]; NSLog(@"%p", self.textField); UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 200, 150, 50)]; label.layer.borderWidth = 1; label.layer.cornerRadius = 10; [self.window addSubview:label]; [label release]; label.tag = 1000; // 控件写成属性, 一定要使用 self.secondText = [[UITextField alloc] initWithFrame:CGRectMake(100, 300, 150, 50)]; self.secondText.backgroundColor = [UIColor cyanColor]; [self.window addSubview:self.secondText]; [self.secondText release]; [self.secondText addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventEditingChanged]; NSLog(@"%p", self.secondText); [_secondText release]; #warning 在给某些控件绑定方法的时候, 一般会在写方法的时候给同一个类型的参数, 哪个控件去执行方法, 对应的参数就是哪个对象, 省去寻找触发事件的对象的麻烦 return YES; } - (void)valueChange:(UITextField *)textfield { // NSLog(@"%@", textfield); // 先通过tag值找到指定的label UILabel *label = (UILabel *)[self.window viewWithTag:1000]; // label.text = textfield.text; if ([self.secondText.text isEqualToString:self.textField.text]) { label.text = @"相同"; } else { label.text = @"不同"; } }
相关文章推荐
- UINT数相减
- ios8 新特性 UITableViewRowAction
- UIButton
- UILabel
- UI_霓虹灯
- 酷友观点/经验:UI设计师不可不知的安卓屏幕知识(原创文章)
- pycharm下pyuic工具使用问题解决方案
- UI01_UIView
- Java序列化及serialVersionUID作用
- UIStackView学习
- Sturts2如何获取request参数
- .net学习笔记----有序集合SortedList、SortedList<TKey,TValue>、SortedDictionary<TKey,TValue>
- ExtJS-Ext.ComponentQuery.query()
- 413 Request Entity Too Large
- 解决NGUI中sprite的边缘会出现黑线的问题
- 设置UIButton字体颜色
- IOS基金会_ UICollectionView简单易用
- xamarin ios UIPickerView
- iOS UI基础-12.0 Storyboard
- UIButton 左对齐 省略号最右边