UITextField

AppDelegate.h

#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 = @"不同";
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值