UITextField

#import "ViewController.h"


@interface ViewController ()
{
    UITextField *textField;
}
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    //注册一个观察者
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(observer) name:UITextFieldTextDidBeginEditingNotification object:nil];
    textField = [[UITextField alloc] initWithFrame:CGRectMake(10,20,300,30)];
    [self.view addSubview:textField];
    //textField.text = @"test";
    textField.textColor = [UIColor redColor];
    textField.font = [UIFont boldSystemFontOfSize:20];
    textField.placeholder = @"请输入内容!";
    textField.textAlignment = NSTextAlignmentCenter;
    //textField.borderStyle = UITextBorderStyleBezel;
    //textField.borderStyle = UITextBorderStyleLine;
    textField.borderStyle = UITextBorderStyleRoundedRect;
    textField.clearsOnBeginEditing = YES;
    //自适应
    textField.adjustsFontSizeToFitWidth = YES;
    textField.minimumFontSize = 3;
    //显示清楚按钮
    textField.clearButtonMode = UITextFieldViewModeWhileEditing;
    UIView *leftView = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
    leftView.backgroundColor = [UIColor greenColor];
    //账号icon之类的用leftView设置
    textField.leftView = leftView;
    textField.leftViewMode = UITextFieldViewModeAlways;
    UIView *rightView = [[UIView alloc] initWithFrame:CGRectMake(0,0,30,30)];
    rightView.backgroundColor = [UIColor greenColor];
    textField.rightView = rightView;
    textField.rightViewMode = UITextFieldViewModeUnlessEditing;

    UIView *inputView = [[UIView alloc] initWithFrame:CGRectMake(0,0,0,60)];
    inputView.backgroundColor = [UIColor grayColor];
    UILabel *label  = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,60)];
    label.text = @"hello i'm em......";
    label.textColor = [UIColor whiteColor];
    [inputView addSubview:label];
    //键盘区域
    //textField.inputView = inputView;
    //键盘扩展区域
    textField.inputAccessoryView = inputView;

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    //textField.resignFirstResponder;
    [textField endEditing:YES];
}
-(void)observer{
    NSLog(@"recive message");
};


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值