1、调整iOS11导航按钮间距:
- (void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
if (@available(iOS 11.0, *)) {
[self adjustRightItemForiOS11];
}
}
//调整iOS11导航按钮间距
- (void)adjustRightItemForiOS11{
UINavigationItem * item=self.navigationItem;
NSArray * array=item.leftBarButtonItems;
if (array&&array.count!=0){
UIBarButtonItem * buttonItem=array[0];
UIView * view =[[[buttonItem.customView superview] superview] superview];
NSArray * arrayConstraint=view.constraints;
for (NSLayoutConstraint * constant in arrayConstraint) {
if (fabs(constant.constant)==16) {
constant.constant=0;
}
}
}
}
2、转Json字符串:
+(NSString *)convertToJsonData:(NSDictionary *)dict {
NSError *error;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:&error];
NSString *jsonString;
if (!jsonData) {
NSLog(@"%@",error);
}else{
jsonString = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];
}
NSMutableString *mutStr = [NSMutableString stringWithString:jsonString];
NSRange range = {0,jsonString.length};
//去掉字符串中的空格
[mutStr replaceOccurrencesOfString:@" " withString:@"" options:NSLiteralSearch range:range];
NSRange range2 = {0,mutStr.length};
//去掉字符串中的换行符
[mutStr replaceOccurrencesOfString:@"\n" withString:@"" options:NSLiteralSearch range:range2];
return mutStr;
}
3、某个页面是否显示导航栏:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated{
[self.navigationController setNavigationBarHidden:[viewController isKindOfClass:self.class]||[viewController isKindOfClass:yunYingViewController.class] animated:YES];
}
4、弹框再pop页面:
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.navigationController popViewControllerAnimated:YES];
});
5、根据时间戳显示时分秒:
+ (NSString *)getMMSSFromSS:(NSInteger )seconds{
NSString *str_day = [NSString stringWithFormat:@"%ld",seconds/3600/24];
//format of hour
NSString *str_hour = [NSString stringWithFormat:@"%02ld",seconds/3600%24];
//format of minute
NSString *str_minute = [NSString stringWithFormat:@"%02ld",(seconds%3600)/60];
//format of second
NSString *str_second = [NSString stringWithFormat:@"%02ld",seconds%60];
if (str_day.intValue>0) {
return [NSString stringWithFormat:@"%@%@:%@:%@:%@",str_day,Localized(@"天"),str_hour,str_minute,str_second];
}
//format of time
return [NSString stringWithFormat:@"%@:%@:%@",str_hour,str_minute,str_second];
}
网友评论