IOS中的一些细节

1.跳转到应用商店下载的两种方式:

NSString *str=@"https://itunes.apple.com/cn/app/appName/idappID";

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

appname可以填可不填  appid是自己Itunes上创建应用时的APPID

NSString *str=@"https://itunes.apple.com/cn/app/he-mu-jing-ying-ban/id929523252";

    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];

2.textField长度限制关于中文联想词崩溃的, 添加[textField markedTextRange]==nil判断

if ([textField markedTextRange]==nil) {

       

if (text.length > _max) {

       

        text = [text substringToIndex: _max];

    }

    return text;

    }


3.疯转了数字显示转换的

-(void)setShows:(UIButton *)button withCount:(NSInteger)count{

    if(count==0){

        [button setTitle:@"评论" forState:UIControlStateNormal];

    }else if(count<10000){

        [button setTitle:[NSString stringWithFormat:@"%d",count] forState:UIControlStateNormal];

    }else{//大于10000显示1.2

        CGFloat number=count/10000.0f;

        NSString *title=[NSString stringWithFormat:@"%.1f",number];

        title=[title stringByReplacingOccurrencesOfString:@".0" withString:@""];

        [button setTitle:title forState:UIControlStateNormal];

        

    }

}

4.关于时间显示的:

+(NSString *)formatterSinaDateToBeforeTime:(NSString *)dateString{

    NSDateFormatter *dateFormatter=[[NSDateFormatter alloc] init];

   

//1.设置新浪微博的时间的日期格式 获取新浪API的时间戳

    dateFormatter.dateFormat=@"EEE MMM d HH:mm:ss Z yyyy";

    //必须设置locale,否则无法解析

    dateFormatter.locale=[[NSLocale alloc]initWithLocaleIdentifier:@"en_US"];

    //    dateFormatter.dateFormat=@"EEE MMM d HH:mm:ss zzzz yyyy";

    //2.获取格式化后的日期

    NSDate *date=[dateFormatter dateFromString:dateString];

    //3.获取当前时间

    NSDate *now=[NSDate date];

    //4.获取当前时间与格式化后的日期的时间差

    NSTimeInterval sinceDate=[now timeIntervalSinceDate:date];

    //5.判断时间差该显示的内容

//    NSString *timeDescription;

    if (sinceDate<60) {//1分钟以内

        return @"刚刚";

    }else if (sinceDate<60*60){//1消失以内

        return [NSString stringWithFormat:@"%.f分钟前",sinceDate/60];

    }else if (sinceDate<60*60*24){//一天以内

        return [NSString stringWithFormat:@"%.f小时前",sinceDate/60/60];

    }else{

        dateFormatter.dateFormat=@"MM-dd HH:mm";

        return [dateFormatter stringFromDate:date];

    }

}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值