iOS 小知识点

宏定义的AlertView

 #define kTipAlert(_S_, ...)     [[[UIAlertView alloc] initWithTitle:@"提示" message:[NSString stringWithFormat:(_S_), ##__VA_ARGS__] delegate:nil cancelButtonTitle:@"知道了" otherButtonTitles:nil] show]

隐藏状态栏

[[UIApplication sharedApplication]setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];

判断对象是否为空

{
    if ([self isEqual:[NSNull null]])
    {
        return YES;
    }
    else
    {
        if ([self isKindOfClass:[NSNull class]])
        {
            return YES;
        }
        else
        {
            if (self==nil)
            {
                return YES;
            }
        }
    }
    if ([self isKindOfClass:[NSString class]]) {
        if ([((NSString *)self) isEqualToString:@"(null)"]) {
            return YES;
        }
    }
    return NO;
}

跳转到App Store的评价页面

NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=你的AppId" ];
if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)){
    str = [NSString stringWithFormat:@"https://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=你的AppId&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8"];
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

UIColor宏定义

// 随机颜色 #define RANDOM_COLOR [UIColor colorWithRed:arc4random_uniform(256) / 255.0 green:arc4random_uniform(256) / 255.0 blue:arc4random_uniform(256) / 255.0 alpha:1]
// 颜色(RGB)#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
// 利用这种方法设置颜色和透明值,可不影响子视图背景色#define RGBACOLOR(r, g, b, a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

数组中的数据求和、最大/小值、平均值

NSArray *arr = [NSArray arrayWithObjects:@"3",@"4",@"2",@"5",@"8", nil];
     /**
      *  求和
      */
     CGFloat sum = [[arr valueForKeyPath:@"@sum.floatValue"] floatValue];
     /**
      *  平均值
      */
     CGFloat avg = [[arr valueForKeyPath:@"@avg.floatValue"] floatValue];
     /**
      *  最大值
      */
     CGFloat max = [[arr valueForKeyPath:@"@max.floatValue"] floatValue];
     /**
      *  最小值
      */
     CGFloat min = [[arr valueForKeyPath:@"@min.floatValue"]floatValue];

你可能感兴趣的:(iOS 小知识点)