1、程序间跳转实现代码:
NSURL*url = [NSURLURLWithString:[NSStringstringWithFormat:@"taobao://"]];
// 判断当前系统是否有安装淘宝客户端
if ([[UIApplication sharedApplication] canOpenURL:url]) {
// 如果已经安装淘宝客户端,就使用客户端打开链接
[[UIApplication sharedApplication] openURL:url];
} else {
// 否则使用 Mobile Safari 或者内嵌 WebView 来显示
url = [NSURL URLWithString:[NSStringstringWithFormat:@"https://www.taobao.com"]];
[[UIApplication sharedApplication] openURL:url];
// 判断当前系统是否有安装淘宝客户端
if ([[UIApplication sharedApplication] canOpenURL:url]) {
// 如果已经安装淘宝客户端,就使用客户端打开链接
[[UIApplication sharedApplication] openURL:url];
} else {
// 否则使用 Mobile Safari 或者内嵌 WebView 来显示
url = [NSURL URLWithString:[NSStringstringWithFormat:@"https://www.taobao.com"]];
[[UIApplication sharedApplication] openURL:url];
}
2、实现屏幕截图代码:
-(UIImage*) makeImage {
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
UIGraphicsBeginImageContext(self.view.bounds.size);
[self.view.layerrenderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return viewImage;
}
5、
CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view setTransform:transform];
11.
16. 导航栏标题颜色
3、判断是什么设备
- if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {...}
4、判断版本型号
[[UIDevicecurrentDevice].systemVersionfloatValue] >=7.0
5、
提高cell流畅度
如果cell要求是圆角,添加下面这句话会减少UI卡顿
cell.layer.shouldRasterize = YES;
和添加阴影有关,减少卡顿
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
如果cell要求是圆角,添加下面这句话会减少UI卡顿
和添加阴影有关,减少卡顿
6、图片进行缩操作:
/*!
*
* 压缩图片至目标尺寸
*
* @param sourceImage 源图片
* @param targetWidth 图片最终尺寸的宽
*
* @return 返回按照源图片的宽、高比例压缩至目标宽、高的图片
*/
- (UIImage *)compressImage:(UIImage *)sourceImage toTargetWidth:(CGFloat)targetWidth {
CGSize imageSize = sourceImage.size;
CGFloat width = imageSize.width;
CGFloat height = imageSize.height;
CGFloat targetHeight = (targetWidth / width) * height;
UIGraphicsBeginImageContext(CGSizeMake(targetWidth, targetHeight));
[sourceImage drawInRect:CGRectMake(0, 0, targetWidth, targetHeight)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
7、tableview回到顶部位置
[self.tableView setContentOffset:CGPointMake(0, 0) animated:YES];
设置scrollsToTop = YES;这个属性,点击状态栏就可以返回顶部了。
8、调用颜色设置代码
#define RGB(__r, __g, __b) [UIColor colorWithRed:(
1.0
*(__r)/
255
)\
green:( 1.0 *(__g)/ 255 )\
blue:( 1.0 *(__b)/ 255 )\
green:( 1.0 *(__g)/ 255 )\
blue:( 1.0 *(__b)/ 255 )\
alpha:1.0]
9、屏幕旋转CGAffineTransform transform = CGAffineTransformMakeRotation(M_PI/2);
[self.view setTransform:transform];
10.关键字高亮
NSString *data;//字符串
NSRange range = [data rangeOfString:@"your keyword"];//"your keyword
"是你需要的关键字
NSMutableAttributedString *attr;
[attr setAttributes:@{NSForegroundColorAttributeName: yourColor
range:range]; //yourColor
是你需要的关键字的颜色,这个字典中还可以添加其他你需要的属性
11.
#if 0
所有内容忽略
#endif
在debug模式下NSLog生效,其他模式不生效
#ifdef DEBUG // 处于开发阶段
#define MXLog(...) NSLog(__VA_ARGS__)
#else // 发布阶段
#define MXLog(...)
#ifdef DEBUG
#define NSDebugLog(format, ...) NSLog((@ "\n[ 函数名 :%s]" "[行号:%d] \n"format "\n"), __FUNCTION__, __LINE__, ## __VA_ARGS__)
#else
#define NSDebugLog(format, ...)
#define NSDebugLog(format, ...) NSLog((@ "\n[ 函数名 :%s]" "[行号:%d] \n"format "\n"), __FUNCTION__, __LINE__, ## __VA_ARGS__)
#else
#define NSDebugLog(format, ...)
#endif
12.iOS9网络请求更改:
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
13.将非ARC文件转换成ARC文件:-fobjc-arc 将ARC文件转化成非ARC文件:-fno-objc-arc
14.
当工程中用到了PCH文件的时候要对其路径进行修改程序中写入PCH 文件路径用$(SRCROOT)+文件
15.当Xcode安装一些插件产生错误无法生效的情况下输入如下路径进行删除插件重新安装
Xcode 插件路径: ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
16. 导航栏标题颜色
UIColor *color = [UIColor whiteColor];
NSDictionary *dict = [NSDictionary dictionaryWithObject:color forKey:NSForegroundColorAttributeName];
[UINavigationBar appearance].titleTextAttributes = dict;
// 改变状态栏颜色UIStatusBarStyleLightContent(白色)
[[UIApplication sharedApplication]setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];