一,效果图。
二,工程图。
三,代码。
ViewController.m
- (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;
}
}