2016.11.27-2017.02.25
一睛约、 時(shí)間與時(shí)間戳的相互轉(zhuǎn)換
借鑒資料:
http://blog.csdn.net/laomaoios/article/details/43899551
http://www.superqq.com/blog/2015/06/26/nsdatehe-nsstringxiang-hu-zhuan-huan/
示例代碼:
///時(shí)間戳轉(zhuǎn)換為時(shí)間
+ (NSString *) timestampConversionDate:(NSInteger)time {
NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *dateformatter=[[NSDateFormatter alloc] init];
[dateformatter setDateFormat:@"YYYY.MM.dd. HH:mm"];
NSString *timeStr=[dateformatter stringFromDate:date];
return timeStr;
}
二、UIButton的title和image位置變換
借鑒資料:
http://www.reibang.com/p/fb20bce230d9 //改變UIButton的相對(duì)布局
http://www.reibang.com/p/43c22fa3b42c //擴(kuò)大UIButton的可點(diǎn)擊范圍
三恬试、如何異步線程同步請(qǐng)求
示例代碼:
dispatch_group_t group = dispatch_group_create();
dispatch_group_enter(group);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[strongSelf getAllVideoDataFoundation];//請(qǐng)求數(shù)據(jù)函數(shù)一
[strongSelf getDataFouncation]; //請(qǐng)求數(shù)據(jù)函數(shù)二
...... //請(qǐng)求數(shù)據(jù)函數(shù)N
dispatch_group_leave(group);
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
});
四审丘、復(fù)制字符串到剪切板
借鑒資料:
http://www.reibang.com/p/ef738baf8e33
代碼示例:
UIPasteboard *pasteboard = [UIPasteboard generalPasteboard];
[pasteboard setString:copyString];
五吏够、調(diào)用系統(tǒng)功能與跳轉(zhuǎn)到系統(tǒng)設(shè)置
借鑒資料:
http://www.reibang.com/p/78db0e46d954
代碼示例:
UIWebView *webView = [[UIWebView alloc] init];
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"tel://%@",number]]]]; //必須加 *tel://*
[self.view addSubview:webView];
六、更改系統(tǒng)彈出框
七滩报、如何縮小導(dǎo)航欄的點(diǎn)擊范圍
//左按鈕:在真正按鈕的旁邊添加一個(gè)空白的左視圖
self.leftButton = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, Size(40), Size(40))];
UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:self.leftButton];
UIBarButtonItem *spaceItem = [[UIBarButtonItem alloc]initWithCustomView:[UIButton buttonWithType:UIButtonTypeCustom]];
self.navigationItem.leftBarButtonItems = [NSArray arrayWithObjects:item,spaceItem,nil];
八锅知、局部或全局隱藏狀態(tài)欄
借鑒資料:
http://www.reibang.com/p/4b2aa09bee06
實(shí)例代碼
if ([self respondsToSelector:@selector(setNeedsStatusBarAppearanceUpdate)]) {
[self prefersStatusBarHidden];
[self performSelector:@selector(setNeedsStatusBarAppearanceUpdate)];
}
- (BOOL)prefersStatusBarHidden {
return YES;
}
九、UIView漸變顏色值
實(shí)例代碼
//初始化CAGradientlayer對(duì)象脓钾,使它的大小為UIView的大小
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = CGRectMake(0, 0, leftProgressWidth, Size1080(21));
//設(shè)置漸變區(qū)域的起始和終止位置(范圍為0-1)
gradientLayer.startPoint = CGPointMake(0, 0.5);
gradientLayer.endPoint = CGPointMake(0.5 , 1);
//設(shè)置顏色數(shù)組
gradientLayer.colors = @[(__bridge id)[UIColor colorWithRGB:color(f9664d)].CGColor,(__bridge id)[UIColor colorWithRGB:color(f83931)].CGColor];
//設(shè)置顏色分割點(diǎn)(范圍:0-1)
gradientLayer.locations = @[@(0.5f)];
//將CAGradientlayer對(duì)象添加在我們要設(shè)置背景色的視圖的layer層
[self.progressView.layer addSublayer:gradientLayer];
十售睹、獲取主Window和刪除特定View
實(shí)例代碼:
UIWindow *keywindow = [[UIApplication sharedApplication] keyWindow]; //獲取主Window
[[[[UIApplication sharedApplication]keyWindow] viewWithTag:1234567]removeFromSuperview]; //刪除特定的tag值得View
十一、內(nèi)購(gòu)Demo
https://github.com/976431yang/YQInAppPurchaseTool
注意:需集成以上Demo里面的內(nèi)購(gòu)Tool
實(shí)例代碼:
///點(diǎn)擊虛擬物品按鈕之后觸發(fā)的方法
- (void)buttonClickEvents: (UIButton *)button {
[YFWLHUDManager showInfoMessage:@"正在購(gòu)買商品"];
if (self.productArray.count > 0) {
[[YFWLInAppPurchaseTool defaultTool]restorePurchase];
[[YFWLInAppPurchaseTool defaultTool]buyProduct:((SKProduct *)self.productArray.firstObject).productIdentifier];
}else {
[YFWLHUDManager showInfoMessage:@"沒有可購(gòu)買的商品"];
}///productArray:productId數(shù)組
}
///內(nèi)購(gòu)基本設(shè)置
- (void) appPurchaseBaseSetting {
//獲取單例
YFWLInAppPurchaseTool *appPurchase = [YFWLInAppPurchaseTool defaultTool];
//設(shè)置代理
appPurchase.delegate = self;
//驗(yàn)證購(gòu)買結(jié)果
appPurchase.CheckAfterPay = YES;
//詢問消息
[YFWLHUDManager showInfoMessage:@"商品是否可以購(gòu)買"];
//向蘋果詢問商品是否能夠購(gòu)買
[appPurchase requestProductsWithProductArray:@[@"123456789"]];
}
#pragma mark - YQInAppPurchaseToolDelegate
///已經(jīng)獲得可購(gòu)買的商品
- (void)IAPToolGotProducts:(NSMutableArray *)products {
self.productArray = products;
if (products.count > 0) {
[YFWLHUDManager showSuccessMessage:@"成功獲取到可購(gòu)買的商品"];
}else {
[YFWLHUDManager showFailureMessage:@"沒有獲取到可購(gòu)買的商品"];
}
}
///支付失敗/取消
- (void)IAPToolCanceldWithProductID:(NSString *)productID {
[YFWLHUDManager showFailureMessage:@"購(gòu)買失敗"];
}
///支付成功惭笑,并開始驗(yàn)證
- (void)IAPToolBeginCheckingdWithProductID:(NSString *)productID {
[YFWLHUDManager showInfoMessage:@"請(qǐng)求成功侣姆,正在驗(yàn)證"];
}
///重復(fù)驗(yàn)證
- (void)IAPToolCheckRedundantWithProductID:(NSString *)productID {
[YFWLHUDManager showInfoMessage:@"重復(fù)驗(yàn)證"];
}
///商品完全購(gòu)買成功
- (void)IAPToolBoughtProductSuccessedWithProductID:(NSString *)productID andInfo:(NSDictionary *)infoDic {
[YFWLHUDManager showSuccessMessage:@"購(gòu)買成功"];
}
///驗(yàn)證失敗
- (void)IAPToolCheckFailedWithProductID:(NSString *)productID andInfo:(NSData *)infoData {
[YFWLHUDManager showFailureMessage:@"驗(yàn)證失敗生真,已取消購(gòu)買"];
}
///恢復(fù)購(gòu)買商品
- (void)IAPToolRestoredProductID:(NSString *)productID {
[YFWLHUDManager showInfoMessage:@"恢復(fù)了商品"];
}
///內(nèi)購(gòu)系統(tǒng)錯(cuò)誤
- (void)IAPToolSysWrong {
[YFWLHUDManager showFailureMessage:@"服務(wù)器繁忙沉噩,請(qǐng)稍后再試"];
}
如有錯(cuò)誤 歡迎指正