拉伸圖片不失真數組
self.imageView.image=[[UIImage imageNamed:@""] stretchableImageWithLeftCapWidth:5 topCapHeight:30];併發
阻止鎖屏,屏幕常亮
常亮 [ [ UIApplication sharedApplication] setIdleTimerDisabled:YES ] ;app
獲取main storyboard
UIStoryboard *stoaryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
LoginViewController *login = [stoaryboard instantiateViewControllerWithIdentifier:@"LoginViewController"];ide
圖片數組播放
_AnimationImage =[[UIImageView alloc]initWithFrame:CGRectMake(0,20, SCREEN_WIDTH, 100)];
[self.view addSubview:_AnimationImage];
_AnimationImage.animationImages = _ImageDatas;
_AnimationImage.animationDuration=1;
[_AnimationImage startAnimating];url
//0則不打印任何東西
#if 1component
#define NSLog(FORMAT, ...) fprintf(stderr,"[%s:%d行] %s\n",[[[NSString stringWithUTF8String:__FILE__] lastPathComponent] UTF8String], __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#elseorm
#define NSLog(FORMAT, ...) nil對象
#endif圖片
循環遍歷開發
for(... in ...)用起來很是方便、簡潔,同時 enumerateObjectsUsingBlock: 也有不少新特性:
* 一般enumerateObjectsUsingBlock: 和 (for(... in ...)在效率上基本一致,有時會快些。主要是由於它們都是基於 NSFastEnumeration 實現的. 快速迭代在處理的過程當中須要多一次轉換,固然也會消耗掉一些時間. 基於Block的迭代能夠達到本機存儲同樣快的遍歷集合. 對於字典一樣適用,而數組的迭代卻不行。
* 注意"enumerateObjectsUsingBlock" 修改局部變量時, 你須要聲明局部變量爲 __block 類型.
* enumerateObjectsWithOptions:usingBlock: 支持併發迭代或反向迭代,併發迭代時效率也很是高.
* 對於字典而言, enumerateObjectsWithOptions:usingBlock 也是惟一的方式能夠併發實現恢復Key-Value值.
跳轉到設置
NSURL*url=[NSURL URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication]openURL:url];
isKindOfClass來肯定一個對象是不是一個類的成員,或者是派生自該類的成員
isMemberOfClass只能肯定一個對象是不是當前類的成員
判斷字符串包含某個字符
[numberString containsString:@"."];
[numberString rangeOfString:@"."].location != NSNotFound;
系統軟件的分享
NSArray *objectsToShare = @[@"http://www.baidu.com"];
UIActivityViewController *controller = [[UIActivityViewController alloc] initWithActivityItems:objectsToShare applicationActivities:nil];
NSArray *excludedActivities = @[UIActivityTypePostToTwitter, UIActivityTypePostToFacebook,
UIActivityTypePostToWeibo,
UIActivityTypeMessage, UIActivityTypeMail,
UIActivityTypePrint, UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo];
controller.excludedActivityTypes = excludedActivities;
// Present the controller
[self presentViewController:controller animated:YES completion:nil];
截圖,合成圖片
//截圖
UIGraphicsBeginImageContext(self.view.bounds.size); //currentView 當前的view
[self.view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
CGRect rect = CGRectMake(0, self.view.frame.size.height-228, self.view.frame.size.width,228);
UIImage *resultImg = [UIImage imageWithCGImage:CGImageCreateWithImageInRect(viewImage.CGImage, rect)];
//拼合
[image1 drawInRect:CGRectMake(0, 0, image1.size.width, image1.size.height)];
// Draw image2
[image2 drawInRect:CGRectMake(0, 0, image2.size.width, image2.size.height)];
UIImage *resultingImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
惟一標識符
NSString *identifierForVendor = [[UIDevice currentDevice].identifierForVendor UUIDString];
NSString *identifierForAdvertising = [[ASIdentifierManager sharedManager].advertisingIdentifier UUIDString];
identifierForVendor對供應商來講是惟一的一個值,也就是說,由同一個公司發行的的app在相同的設備上運行的時候都會有這個相同的標識符。然而,若是用戶刪除了這個供應商的app而後再從新安裝的話,這個標識符就會不一致。
advertisingIdentifier會返回給在這個設備上全部軟件供應商相同的 一個值,因此只能在廣告的時候使用。這個值會由於不少狀況而有所變化,好比說用戶初始化設備的時候便會改變。
利用 NSSetUncaughtExceptionHandler,當程序異常退出的時候,能夠先進行處理,而後作一些自定義的動做,好比下面一段代碼,就是網上有人寫的,直接在發生異常時給某人發送郵件, 使用@try、catch捕獲異常: 如下是最簡單的代碼寫法,其中@finally能夠去掉: @try { // 可能會出現崩潰的代碼 } @catch (NSException *exception) { // 捕獲到的異常exception } @finally { // 結果處理 } - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Override point for customization after application launch. NSSetUncaughtExceptionHandler(&UncaughtExceptionHandler); return YES; } void UncaughtExceptionHandler(NSException *exception) { /** * 獲取異常崩潰信息 */ NSArray *callStack = [exception callStackSymbols]; NSString *reason = [exception reason]; NSString *name = [exception name]; NSString *content = [NSString stringWithFormat:@"========異常錯誤報告========\nname:%@\nreason:\n%@\ncallStackSymbols:\n%@",name,reason,[callStack componentsJoinedByString:@"\n"]]; /** * 把異常崩潰信息發送至開發者郵件 */ NSMutableString *mailUrl = [NSMutableString string]; [mailUrl appendString:@"mailto:test@qq.com"]; [mailUrl appendString:@"?subject=程序異常崩潰,請配合發送異常報告,謝謝合做!"]; [mailUrl appendFormat:@"&body=%@", content]; // 打開地址 NSString *mailPath = [mailUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:mailPath]]; }