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