IOS常用宏及方法等

#define APPDELEGATE [(AppDelegate*)[UIApplication sharedApplication] delegate]
#define IOS7_OR_LATER ([[[UIDevice currentDevice] systemVersion] compare:@"7.0"] != NSOrderedAscending)
#define ISPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define iPhone5 ([UIScreen instancesRespondToSelect or:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define RGBCOLOR(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]

inline static NSString * compareCurrentTime(NSDate* compareDate)
//
{
    NSTimeInterval   timeInterval = [compareDate timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumSty le];
    [formatter setTimeStyle:NSDateFormatterShortStyl e];
     
    if (timeInterval < 60) {
        result = [NSString stringWithFormat:@"刚刚"];
    }
    else if((temp = timeInterval/60) <60){
        result = [NSString stringWithFormat:@"%ld分钟前",temp];
    }
     
    else if((temp = temp/60) <24){
        result = [NSString stringWithFormat:@"%ld小时前",temp];
    }
     
    else if((temp = temp/24) <30){
        // result = [NSString stringWithFormat:@"%ld天前",temp];
        [formatter setDateFormat:@"MM"];
        NSString* monthString = [formatter stringFromDate:compareDate];
        int month = [monthString intValue];
        if (month < 10) {
            [formatter setDateFormat:@"M月dd日"];
        }
        else
        {
            [formatter setDateFormat:@"MM月dd日"];
        }
        result = [formatter stringFromDate:compareDate];
    }
     
    else if((temp = temp/30) <12){
        [formatter setDateFormat:@"MM"];
        NSString* monthString = [formatter stringFromDate:compareDate];
        int month = [monthString intValue];
        if (month < 10) {
            [formatter setDateFormat:@"M月dd日"];
        }
        else
        {
            [formatter setDateFormat:@"MM月dd日"];
        }
        //result = [NSString stringWithFormat:@"%ld月前",temp];
        [formatter setDateFormat:@"MM月dd日"];
        result = [formatter stringFromDate:compareDate];
    }
    else{
        temp = temp/12;
        //result = [NSString stringWithFormat:@"%ld年前",temp];
        [formatter setDateFormat:@"yyyy年MM月dd日"];
        result = [formatter stringFromDate:compareDate];
    }
     
    return   result;
}


//获取当前时间时间戳
inline static NSString *getNowTimeLine()
{
    NSDate* now = [NSDate dateWithTimeIntervalSinc eNow:0];
    NSTimeInterval ttt=[now timeIntervalSince1970]*1000;
    NSString *timeString = [NSString stringWithFormat:@"%f", ttt];
    return timeString;
}
//获取视图在父视图的绝对位置
inline static CGRect getCGRectInScreenFromVie w(UIView *view,UIView *superView)
{
    CGRect frame = [view convertRect:view.bounds toView:superView];
    return frame;
}


//时间戳转为时间字符串

inline static NSString *getStandaredTimeOfYearMo nthDayFromtimeStamp(NSString *timestamp)
{
    NSDate *date = [NSDate dateWithTimeIntervalSinc e1970:[timestamp floatValue]];
    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
    [formatter setDateStyle:NSDateFormatterMediumSty le];
    [formatter setTimeStyle:NSDateFormatterShortStyl e];
    [formatter setDateFormat:@"yyyy年MM月dd日"];
    NSString *resultString = [formatter stringFromDate:date];
    return resultString;
}

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

IOS常用宏及方法等

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值