效果图:
代码:
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. //TextField UITextField *textField=[[UITextField alloc]initWithFrame:CGRectMake(20, 100, 100, 200)]; textField.backgroundColor=[UIColor redColor]; textField.text=@"123"; [self.view addSubview:textField]; NSLog(@"判断textField里面是否为空%i",[self textFieldIsNOTEmpt:textField]); }//判断textField里面是否有空-(BOOL)textFieldIsNOTEmpt:(UITextField *)textField{ if ([textField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]].length!=0){ return YES; }else { return NO; }}