1.去除NSString字符串里面的特殊符号
-(NSString*)deleteSpecificSymbolForString:(NSString*)text{
//先创建NSCharacterSet,把需要去除的字符串放在里面
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/::;;¥「」"、[]{}#%-*+=_\|~<>$€^?'@#$%^&*()()_+'""];
//该方法返回的是去除特殊符号后的字符串
NSString *trimmedString = [text stringByTrimmingCharactersInSet:set];
return trimmedString;
}
  2.判断NSString字符串里面有没有汉字
-(BOOL)estimateStringContainChinese:(NSString*)text{
if(text){
for (int i=0; i<text.length; i++) {
NSRange range = NSMakeRange(i,1);
NSString *subString = [text substringWithRange:range];
const char *cString = [subString UTF8String];
if (strlen(cString) == 3){ //代表有汉字
return YES;
}
}
}
return NO;
}
  3.判断NSString字符串里面有没有英文字母
-(BOOL)estimateStringContainEnglish:(NSString*)text{
if(text){
for (int i=0; i<text.length; i++) {
NSRange range = NSMakeRange(i,1);
NSString *subString = [text substringWithRange:range];
const char *cString = [subString UTF8String];
if (strlen(cString) == 1){ //代表有英文
return YES;
}
}
}
return NO;
}
  4.在指定控制器里面更改状态栏文字颜色
  每一个应用程序,应该都会有统一的导航栏和状态栏风格。但是有时候,也有需要在指定控制器里面修改
  状态栏的风格,如:播放视频。
  -(void)viewWillAppear:(BOOL)animated{
  [super viewWillAppear:animated];
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:YES];
  }
  -(void)viewWillDisappear:(BOOL)animated{
  [super viewWillDisappear:animated];
  [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
  }
  5.点击进入搜索控制器时,自动弹出键盘,让搜索框进入编辑状态
  当点击搜索时,进入搜索控制器,使用系统自带的搜索框,searchController.searchBar,进入时,自动实现如下图的效果
  效果图.png
  找了很多方法,下面这个是有效方法:
  - (void)viewDidAppear:(BOOL)animated {
  [super viewDidAppear:animated];
  [self performSelector:@selector(showKeyboard) withObject:nil afterDelay:0];
  }
  - (void)showKeyboard {
  [self.searchController.searchBar becomeFirstResponder];
  }
  6.修改系统自带搜索框的UI
  系统自带的搜索框,使用方便快捷,但是有时候它的外观与要求不符,这时候需要我们来对系统搜索框
  进行一些修改
for (UIView* subview in [[self.searchController.searchBar.subviews lastObject] subviews]) {
//相当于UITextField,输入框,可以修改背景颜色等
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarTextField")]) {
UITextField *textField = (UITextField*)subview;
[textField setBackgroundColor:COLOR_RGB(238, 238, 238)];
}
//相当于UIButton,搜索框右侧的Cancle按钮,可以修改默认文字等
if ([subview isKindOfClass:NSClassFromString(@"UINavigationButton")]) {
UIButton* cancle = (UIButton*)subview;
[cancle setTitle:@"取消" forState:UIControlStateNormal];
[cancle setTitleColor:COLOR_RGB(82, 184, 255) forState:UIControlStateNormal];
}
//相当于UIView,搜索框的背景view,一般将它去掉,然后自己添加一层背景view
if ([subview isKindOfClass:NSClassFromString(@"UISearchBarBackground")]) {
[subview removeFromSuperview];
UIView* back = [[UIView alloc]initWithFrame:self.searchController.searchBar.bounds];
back .backgroundColor = [UIColor whiteColor];
[self.searchController.searchBar insertSubview:back atIndex:0];
}
}
  7.在指定控制器中隐藏导航栏
  有时候,需要在指定控制器中隐藏导航栏,试过好几个方法,或多或少有些坑,下面这个是我认为比较好的:
  首先让该控制器成为导航栏的代理:
  self.navigationController.delegate = self;
  然后,实现指定的代理方法:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
if ([viewController isKindOfClass:[self class]]) {
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
//返回时,在指定控制器重新让导航栏显示
if ([viewController isKindOfClass:[ContactVC class]]) {
[self.navigationController setNavigationBarHidden:NO animated:YES];
}
}