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];

    }

}




發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章