文章标题

来源:互联网 发布:淘宝店铺开通直播 编辑:程序博客网 时间:2024/06/03 22:47
@interface AppDelegate ()<UITextFieldDelegate>@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]];    // Override point for customization after application launch.    self.window.backgroundColor = [UIColor whiteColor];    [self.window makeKeyAndVisible];    [_window release];    // 创建一个Button    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];    button.frame = CGRectMake(100, 100, 150, 50);    button.backgroundColor = [UIColor redColor];    [self.window addSubview:button];    // Button 用便利构造器创建, 不需要释放    button.layer.cornerRadius = 10;    button.layer.borderWidth= 1;    // 添加一个标题    [button setTitle:@"确认" forState:UIControlStateNormal];    // 修改字体大小    button.titleLabel.font = [UIFont systemFontOfSize:25];    // 改字体颜色    [button setTitleColor:[UIColor blackColor] 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;    // 设置代理人    self.textField.delegate = self;    return YES;}// 点击return 回收键盘- (BOOL)textFieldShouldReturn:(UITextField *)textField {    // 失去第一响应者    [textField resignFirstResponder];    return YES;}- (void)click:(UIButton *)button {    if ([button.currentTitle isEqualToString:@"确认"]  ) {        [button setTitle:@"取消" forState:UIControlStateNormal];        NSLog(@"%@", self.textField.text);    } else {        [button setTitle:@"确认" forState:UIControlStateNormal];    }   // 点击确认显示密码, 点击取消隐藏密码    self.textField.secureTextEntry = !self.textField.secureTextEntry;}
0 0