UITextField
来源:互联网 发布:中国联合网络通信缴费 编辑:程序博客网 时间:2024/06/05 18:12
import “AppDelegate.h”
@interface AppDelegate ()
@property(nonatomic, retain)UITextField *secondText;
@property(nonatomic, retain)UITextField *field;
@end
@implementation AppDelegate
- (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];**UITextField** self.field = [[UITextField alloc] initWithFrame:CGRectMake(100, 100, 150, 50)]; self.field.backgroundColor = [UIColor purpleColor]; [self.window addSubview:self.field]; [self.field release];// 加上边框和弧度 self.field.layer.borderWidth = 1; self.field.layer.cornerRadius = 10; self.field.textColor = [UIColor redColor]; self.field.textAlignment = NSTextAlignmentCenter;*强调内容* self.field.placeholder = @"请输入内容"; // 控制能否使用输入框 self.field.enabled = YES; // 密码效果 self.field.secureTextEntry = YES; // 键盘类型 self.field.returnKeyType = UIReturnKeyGo; // UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 200)]; // view.backgroundColor = [UIColor yellowColor]; // // 可以通过自定义的视图,取代键盘 // self.field.inputView = view; // self.field.inputAccessoryView = view;// 清除按钮 self.field.clearButtonMode = UITextFieldViewModeAlways;// 给textField添加一个事件(用textField去调用一个方法) [self.field addTarget:self action:@selector(valueChange:) forControlEvents:UIControlEventEditingChanged]; NSLog(@"%p", self.field); 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", _secondText);#warning 在给某些控件绑定方法的时候, 一般会在写方法的时候给一个同类型的参数,哪个控件去执行方法,对应的参数就是哪个对象,省去寻找出发事件的对象的麻烦 return YES; }
- (void)valueChange:(UITextField *)field { NSLog(@"%@", field.text); *先通过tag值来找到指定的label* UILabel *label = (UILabel *)[self.window viewWithTag:1000]; if([self.secondText.text isEqualToString:self.field.text]) { label.text = @"相同"; } else { label.text = @"不同"; } }
@end
0 0
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- UITextField
- 寻找轮廓
- POJ 3617 Best Cow Line(字典序最小问题)
- 获取SD卡上的文档的内容
- GPU优化思路
- 32.Binary Tree Level Order Traversal
- UITextField
- 面试复盘
- 日经春秋 20151020
- Android中layout_align****和setPadding方法整合
- 菜鸟之路-04
- 判断字符串中只包含字母和数字
- LintCode-最大数
- 黑马程序员——Java基础语法 之程序流程控制
- 高斯模糊效果实现方案及性能对比