一些用到的小方法
1. 获取图片的大小的方法
UIImage * image = [UIImage imageNamed:@"1.png"];
CGSize * size = (__bridge CGSize *)NSStringFromCGSize(image.size);
CGSize * size = (__bridge CGSize *)NSStringFromCGSize(image.size);
NSLog(@“%@",size);
2. 解决 push 到写一个界面的时候导航控制器从隐藏过度到不隐藏的时候出现的闪现现象
[self.navigationController setNavigationBarHidden:NO animated:YES];
3. 打印 deviceToken
NSLog(@"%@",[[[[deviceToken description] stringByReplacingOccurrencesOfString: @"<" withString: @""] stringByReplacingOccurrencesOfString: @">" withString: @""] stringByReplacingOccurrencesOfString: @" " withString: @""]);
4. 设置CGRectZero从导航栏下开始计算
// 设置CGRectZero从导航栏下开始计算
if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
self.edgesForExtendedLayout = UIRectEdgeNone;
}
5. pop 到指定界面
int index = (int)[[self.navigationController viewControllers]indexOfObject:self];
[self.navigationController popToViewController:[self.navigationController.viewControllers objectAtIndex:(index -2)] animated:YES];
6. 去掉导航栏黑线
[self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc]init] forBarMetrics:UIBarMetricsDefault];
[self.navigationController.navigationBar setShadowImage:[[UIImage alloc]init]];
7. 利用arc4random_uniform()产生随机数
Objective-C 中有个arc4random()函数用来生成随机数且不需要种子,但是这个函数生成的随机数范围比较大,需要用取模的算法对随机值进行限制,有点麻烦。
其实Objective-C有个更方便的随机数函数arc4random_uniform(x),可以用来产生0~(x-1)范围内的随机数,不需要再进行取模运算。如果要生成1~x的随机数,可以这么写:arc4random_uniform(x)+1。
8. 修改NavagationController 的字体大小及风格
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[self appearance];
LGViewController *lg = [[LGViewController alloc]initWithFormat:LGViewControllerFormatTapMe];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lg];
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
-(void)appearance
{
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaNeue-Light" size:14], NSFontAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes: textTitleOptions];
}
[self appearance];
LGViewController *lg = [[LGViewController alloc]initWithFormat:LGViewControllerFormatTapMe];
UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:lg];
self.window = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen]bounds]];
self.window.rootViewController = nav;
[self.window makeKeyAndVisible];
return YES;
}
-(void)appearance
{
NSDictionary *textTitleOptions = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont fontWithName:@"HelveticaNeue-Light" size:14], NSFontAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes: textTitleOptions];
}
9. iOS 获取音频或视频的时间
AVURLAsset* audioAsset =[AVURLAssetURLAssetWithURL:audioFileURL options:nil];
CMTime audioDuration = audioAsset.duration;
float audioDurationSeconds =CMTimeGetSeconds(audioDuration);10. 调整进度条的高度
CGAffineTransform transform = CGAffineTransformMakeScale(1.0f, 3.0f);
progressView.transform = transform;
没有那个时代犹如现在,知识的爆发和技术的进步如此的迅速,必须不断的学习才能紧跟时代的步伐 . (PS:资料来源比较复杂 ,如有侵权 , 删)

浙公网安备 33010602011771号