</pre><img src="https://img-blog.csdn.net/20150604212014446?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQUtfRmlzaGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /><img src="https://img-blog.csdn.net/20150604212153919?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvQUtfRmlzaGVy/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="" /> 图片加载前的背景图片<p></p><p><span style="font-size:24px"><span style="">iOS </span><span style="">写plist 文件</span></span></p><p><span style="font-size:24px"><span style=""></span></span></p><pre name="code" class="objc">NSDictionary *dict2=@{@"key1":@"value",@"key2":@"value2"};
// 得到沙盒目录
NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask , YES) ;
NSString *box=[paths objectAtIndex:0];
NSString *filename=[box stringByAppendingPathComponent:@"test.plist"];
NSLog(@" filename = %@",filename) ;
[dict2 writeToFile:filename atomically:YES] ;
读取图片的两种方式
方式一 : 加载大图片,不要缓存 NSBundle *bundle =[NSBundle mainBundle] ; NSString *d =[bundle pathForResource:@"d" ofType:@"jpg"];[UIImage imageWithContentsOfFile:d ]方式二 : 加载重复小图片,且有缓存[UIImage imageNamed:@"1.jpg"];
截屏代码
UIGraphicsBeginImageContextWithOptions(self.view.frame.size, NO, 0.0);
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
NSData *data2 = UIImagePNGRepresentation(newImage);
[data2 writeToFile:@"/Users/apple/Desktop/screen.png" atomically:YES];
</pre>添加水印的代码
- (UIImage *) addLogo:(NSString *) logo ToImage:(NSString *) name {
// logo 是水印 name 是原图
UIImage *oldImg=[UIImage imageNamed:name];
UIGraphicsBeginImageContextWithOptions(oldImg.size, NO, 0.0);
[oldImg drawInRect:CGRectMake(0, 0, oldImg.size.width, oldImg.size.height)];
UIImage *waterImage=[UIImage imageNamed:logo];
CGFloat waterW = 50;
CGFloat waterH = 25;
CGFloat waterX = oldImg.size.width - waterW - 5;
CGFloat waterY = oldImg.size.height - waterH - 5;
CGRect waterRect = CGRectMake(waterX, waterY, waterW, waterH);
[waterImage drawInRect:waterRect];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage ;
}
自定义log
#ifdef DEBUG
#define HHLog(xx,...) NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define HHLog(xx,...)
#endif // 这样在发布app 的时候log 自动关闭
发送本地通知 iOS8 要申请权限
UILocalNotification *local=[[UILocalNotification alloc]init];
local.alertAction=@"alertAction";
UIApplication *app=[UIApplication sharedApplication] ;
if (IOS8) {
UIUserNotificationSettings *settings=[UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeAlert|UIUserNotificationTypeSound categories:nil];
[app registerUserNotificationSettings: settings ];
local.applicationIconBadgeNumber=40;
}else {
local.applicationIconBadgeNumber=10;
}
local.accessibilityLabel=@"accessLabel";
local.alertBody=@"alertBody";
local.repeatInterval=NSCalendarUnitMinute ;
local.fireDate=[NSDate dateWithTimeIntervalSinceNow:5];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[[UIApplication sharedApplication] scheduleLocalNotification:local];
视图抖动
CAKeyframeAnimation *shakeAnim = [CAKeyframeAnimation animation];
shakeAnim.keyPath = @"transform.translation.x";
shakeAnim.duration = 0.15;
CGFloat delta = 10;
shakeAnim.values = @[@0, @(-delta), @(delta), @0];
shakeAnim.repeatCount = 2;
[self.loginView.layer addAnimation:shakeAnim forKey:nil];
</pre><pre name="code" class="objc">SDWebImage加载大图导致的内存警告问题
http://www.wtoutiao.com/a/1402505.html
Reachability 的基本用法
//监测wifi状态
Reachability *wifi=[ReachabilityreachabilityForLocalWiFi];
// 监测手机能否上网
Reachability *conn=[ReachabilityreachabilityForInternetConnection] ;
// 用WIFI
// [wifi currentReachabilityStatus] != NotReachable
// [conn currentReachabilityStatus] != NotReachable
// 没有用WIFI,只用了手机网络
// [wifi currentReachabilityStatus] == NotReachable
// [conn currentReachabilityStatus] != NotReachable
// 没有网络
// [wifi currentReachabilityStatus] == NotReachable
// [conn currentReachabilityStatus] == NotReachable
在mac 上如果需要隐藏某个文件夹 只需要在console 下 重命名文件夹 具体是在前面加“.” 即可 mv ios .ios 如果想显示的话反过来即可。。
iOS 上生成唯一的字符串
方法一:
CFUUIDRef uuidRef =CFUUIDCreate(kCFAllocatorDefault);
NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(kCFAllocatorDefault, uuidRef));
uuidString= [uuidString stringByReplacingOccurrencesOfString:@"-"withString:@""];
方法二;[NSUUIDUUID].UUIDString 只能用在iOS6 之后
图像旋转
CABasicAnimation* rotationAnimation;
rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
rotationAnimation.toValue = [NSNumber numberWithFloat: 0-M_PI * 2.0 ];///* full rotation*/ * rotations * duration ];
rotationAnimation.duration = 1;
rotationAnimation.cumulative = YES;
rotationAnimation.repeatCount = CGFLOAT_MAX;
[button.layer addAnimation:rotationAnimation forKey:nil];
建议 压缩图片 ,可以在子线程进行 然后再主线程设置图片
定义常量
.h UIKIT_EXTERN NSString *const RandomString
.m NSString *contst RandomString =@"多看看看看";
这样在内存中只会有一份,而 定义成宏的方式,则 在使用过程中,使用几次则会占用几次内存
一中比较好的写法 是懒加载的变形
NSArray *arr=({
NSMutableArray *arr=[NSMutableArray array];
for(int i=0;i<5;i++){
[arr addObject:(@1)];
}
arr ;
});
nil NSNull Null 的区别
nil 是给对象付空值 Null 是给指针赋空值 两者不能互换 NSNull 用于集合操作