1、 多個異步任務進行處理,用GCD的dispatch_group_t,還有其他的方法,不過用這個就好了
// 1.創(chuàng)建dispatch_group_t
dispatch_group_t group = dispatch_group_create();
for (int i=0; i<10; i++) {
// 2、將當前的下載操作添加到組中
dispatch_group_enter(group);
{
// 數據請求成功離開當前組
dispatch_group_leave(group);
}
}
// 3.當所有圖片都下載完畢再通過閉包通知調用者
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
// 能夠來到這個地方, 一定是所有任務都已經完成
});
2、給App進行評分
NSString *str = [NSString stringWithFormat:@"itms-apps://ax.itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=xxxxxx" ];
if( ([[[UIDevice currentDevice] systemVersion] doubleValue]>=7.0)){
str = [NSString stringWithFormat:@"itms-apps://itunes.apple.com/app/idxxxxxxx"];
}
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
3、 跳轉進入app的設置界面
NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
NSURL*url =[NSURL
URLWithString:UIApplicationOpenSettingsURLString];
[[UIApplication sharedApplication] openURL:url];
}
4、label設置刪除線
UILabel *originPriceLabel = [UILabel new];
NSString *originPriceString = [NSString stringWithFormat:@"¥ %@0", @"100"];
NSMutableAttributedString *originPriceAttrsStr = [[NSMutableAttributedString alloc] initWithString:originPriceString];
[originPriceAttrsStr addAttribute:NSStrikethroughStyleAttributeName value:@(1)
range:NSMakeRange(0, originPriceString.length)];
originPriceLabel.attributedText = originPriceAttrsStr;
5、 設置textView或者label的行間距方法
UILabel *label = [UILabel new];
label.numberOfLines = 0;
NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
paragraphStyle.lineSpacing = 4;
NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:14], NSParagraphStyleAttributeName:paragraphStyle};
label.attributedText = [[NSAttributedString alloc]initWithString:label.text attributes:attributes];
6、 NSArray倒序
NSArray *arr = [NSArray array];
NSArray *tmparr = [[arr reverseObjectEnumerator] allObjects];
NSLog(@"%@",tmparr);
7、UIImageView設置圓角時產生UI不流暢的解決
// 只需要加上這段代碼就可以去除鋸齒
imageView.layer.shouldRasterize = YES;
當shouldRasterize設成true時,layer被渲染成一個bitmap,并緩存起來,等下次使用時不會再重新去渲染了。實現(xiàn)圓角本身就是在做顏色混合(blending),如果每次頁面出來時都blending,消耗太大,這時shouldRasterize = yes,下次就只是簡單的從渲染引擎的cache里讀取那張bitmap,節(jié)約系統(tǒng)資源。
額外收獲:如果在滾動tableView時,每次都執(zhí)行圓角設置,肯定會阻塞UI,設置這個將會使滑動更加流暢。
原文鏈接:http://blog.csdn.net/zhuangyou123/article/details/8737367
8、 打電話
//1、這種發(fā)放,撥打完電話回不到原來的應用,會停留在通訊錄里面,而且是直接撥打,不彈出提示
NSMutableString * str1=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str1]];
//2,這種方法,打完電話后還會回到原來的程序,也會彈出提示,推薦這種
NSMutableString * str2=[[NSMutableString alloc] initWithFormat:@"tel:%@",@"186xxxx6979"];
UIWebView * callWebview = [[UIWebView alloc] init];
[callWebview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:str2]]];
[self.view addSubview:callWebview];
// 3,這種方法也會回去到原來的程序里(注意這里的telprompt),也會彈出提示
NSMutableString * str3=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",@"186xxxx6979"];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str3]];
//用第3個的時候要小心,因為apple的文檔里邊沒出現(xiàn)過telprompt這個。 之前是有過被reject的案例。