随机数
arc4random()
0-10之间的随机数
arc4random()%10
0-100之间的随机数
arc4random()%100
......
随机颜色
[UIColor colorWithRed: (arc4random()%256/256.0) green: (arc4random()%256/256.0) blue:(arc4random()% 256/256.0) alpha:1]
字符串排序
NSArray * strArray = @[@"as",@"fd",@"bd",@"wd",@"ca"];
NSStringCompareOptions comparisonOptions = NSCaseInsensitiveSearch|NSNumericSearch|NSWidthInsensitiveSearch|NSForcedOrderingSearch;
NSComparator sort = ^(NSString *obj1,NSString *obj2){
NSRange range = NSMakeRange(0,obj1.length);
return [obj1 compare:obj2 options:comparisonOptions range:range];
};
NSArray *resultArray = [strArray sortedArrayUsingComparator:sort];
NSLog(@"%@",resultArray);
改变状态栏颜色
iOS手机状态栏默认是黑色,在某些情况下需要改变状态栏的颜色
在info.plist文件中添加:View controller-based status bar appearance:NO
隐藏状态栏
//隐藏状态栏
if([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]){
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
-(BOOL)prefersStatusBarHidden{
return YES;
}