import “AppDelegate.h”
@interface AppDelegate ()
@property(nonatomic, assign)BOOL isSelected;
@property(nonatomic, retain)UITextField *textField;
@end
@implementation AppDelegate
- (void)dealloc
{
[_window release];
[_textField release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
[_window release];
// 创建一个Button
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(100, 100, 150, 50);
[self.window addSubview:button];
// 添加边框,添加弧度
button.layer.borderWidth = 1;
button.layer.cornerRadius = 10;
// 添加一个标题
// [button setTitle:@"确认" forState:UIControlStateNormal];
// 修改字体大小
// button.titleLabel.font = [UIFont systemFontOfSize:25];
// 修改颜色
// [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
// button上添加图片
// 全铺
// [button setBackgroundImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
// [button setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
// 绑定一个点击方法
[button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
// 创建一个textField
self.textField = [[UITextField alloc] initWithFrame:CGRectMake(100, 200, 150, 50)];
self.textField.layer.borderWidth = 1;
self.textField.layer.cornerRadius = 10;
[self.window addSubview:self.textField];
[_textField release];
self.textField.secureTextEntry = YES;
改变textfiled的SecureTextEntry属性时,给textfiled重新赋值
return YES;
}
// 点击return 回收键盘
- (BOOL)textFieldShoudReturn:(UITextField *)textField {
// 失去第一响应者
[textField resignFirstResponder];
return YES;
}
- (void)click:(UIButton *)button{
NSLog(@"%@", self.textField.text);
if ([button.currentTitle isEqualToString:@"确认"]) {
[button setTitle@"取消" forState:UIControlStateNormal];}
else {
[button setTitle:@"确认" forState:UIControlStateNormal];}
self.textField.secureTextEntry = !self.textField.secureTextEntry;
}