UI 03 UIButton 和 UITextField
来源:互联网 发布:中国原油9月进口数据 编辑:程序博客网 时间:2024/06/06 09:47
可以将UIButton 与 UITextField 结合起来使用, 产生如下图的效果.
// 新建一个Button UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem]; button.frame = CGRectMake(100, 300, 50, 50); button.backgroundColor = [UIColor cyanColor]; [self.window addSubview:button]; button.layer.borderWidth = 1; [button setTitle:@"显示" forState:UIControlStateNormal ]; [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside]; // 新建一个UITextField的属性. self.textField = [[UITextField alloc] initWithFrame:CGRectMake(70, 100, 120, 50)]; self.textField.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.textField]; [self.textField release]; self.textField.textColor = [UIColor cyanColor]; self.textField.layer.borderWidth = 1; self.textField.layer.cornerRadius = 10; self.textField.clearButtonMode = UITextFieldViewModeAlways; self.textField.placeholder = @"请输入密码"; self.textField.secureTextEntry = YES; self.textField.keyboardType = UIKeyboardTypeNumberPad; self.textField.tag = 1000; // 他是UIControl的子类,可以添加addTag 方法 [self.textField addTarget:self action:@selector(chageValue:) forControlEvents:UIControlEventEditingChanged]; //创建一个按钮,用来切换状态 UIButton *newButton = [UIButton buttonWithType:UIButtonTypeCustom]; newButton.frame = CGRectMake(60, 180, 40, 40); newButton.backgroundColor = [UIColor whiteColor]; [self.window addSubview:newButton]; self.isSelect = NO; [newButton setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal]; [newButton addTarget:self action:@selector(changePic:) forControlEvents:UIControlEventTouchUpInside]; // 创建一个label来显示 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110, 180, 150, 40)]; label.backgroundColor = [UIColor whiteColor]; [self.window addSubview:label]; [label release]; label.text = @"是否显示密码"; label.alpha = 0.5; //创建一个label self.label = [[UILabel alloc] initWithFrame:CGRectMake(210, 110, 150, 30)]; self.label.backgroundColor = [UIColor whiteColor]; [self.window addSubview:self.label]; [_label release]; self.label.alpha = 0.5; self.label.text = @"passWord lenth";
对应的方法:
- (void)click:(UIButton *)button{// UITextField *t = (UITextField *)[self.window viewWithTag:1000]; NSLog(@"%@",self.textField.text);}- (void)changePic:(UIButton *)button{ if (self.isSelect) { [button setImage:[UIImage imageNamed:@"check.png"] forState:UIControlStateNormal]; }else{ [button setImage:[UIImage imageNamed:@"checked.png"] forState:UIControlStateNormal]; } self.isSelect = !self.isSelect; self.textField.secureTextEntry = !self.textField.secureTextEntry;}- (void)chageValue:(UITextField *)textField{ NSLog(@"%@",textField.text); if (textField.text.length >5) { self.label.text = @"密码长度适合"; }else{ self.label.text = @"密码长度太短"; }}
从图中还可以看到一个mybutton 字样的button.
那个是新建的继承于UIButton的MyButton 类.
// MyButton类型的对象. MyButton *meButton = [MyButton buttonWithType:UIButtonTypeSystem]; meButton.frame = CGRectMake(200, 250, 100, 100); meButton.buttonName = @"宋某人"; [self.window addSubview:meButton]; [meButton setTitle:@"myButton" forState:UIControlStateNormal];
0 0
- UI 03 UIButton 和 UITextField
- UI - UITextField和UIButton
- UI笔记:UILabel、UIButton和UITextField
- UI第二讲UITextField和UIButton
- UI-UITextField UIButton
- 初始UI(UILabel、UIButton、UITextField)
- UIButton和UITextField
- UIButton和UITextfield
- UITextField和UIButton属性
- UItextField 和 UIbutton
- UI-第二讲UILable、UITextField , UIButton
- UI基本控件-UILabel-UITextField-UIButton-UIAlertView
- iOS UI 第二课 UITextField UIButton
- IOS UI 代码创建UIButton,UITextField,UILabel
- UI课程02 UILabel,UITextField,UIButton
- UI一揽子计划 2 (UITextField UIButton)
- UI-基本控件( UILabel UITextField UIImageView UIButton)
- 【iOS开发】简单UI部分UIButton的创建和UITextField的使用
- list排序
- Linux tr 命令
- wget命令详解,断点续传
- IOS绘图API绘制直线几何图形
- 第二周周一
- UI 03 UIButton 和 UITextField
- HDOJ 5338 ZZX and Permutations 线段树+树状数组
- Xcode6以后segue取消原push与modal(deprecated)
- Linux系统编程(1)——文件与I/O之C标准I/O函数与系统调用I/O
- 状态模式——水之三态
- border-image
- linux下c的共享库和静态库
- 7月20日--8月1日30小时,剩3600小时
- HashTable, HashSet, HashMap的区别