iOS 實用小功能

1 、xib中l(wèi)abel進行換行

    1、label.numberlines = 0; 

    2、xib中將光標移至換行位置,按住option鍵+enter鍵  

2、 多個異步任務(wù)進行處理,用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);

        {

              // 數(shù)據(jù)請求成功離開當前組

                 dispatch_group_leave(group);

        }

}
// 3.當所有圖片都下載完畢再通過閉包通知調(diào)用者

dispatch_group_notify(group, dispatch_get_main_queue(), ^{

         // 能夠來到這個地方, 一定是所有任務(wù)都已經(jīng)完成
});

3、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]];

4、 跳轉(zhuǎn)進入app的設(shè)置界面

NSURL * url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if([[UIApplication sharedApplication] canOpenURL:url]) {
          NSURL*url =[NSURL           
           URLWithString:UIApplicationOpenSettingsURLString];
           [[UIApplication sharedApplication] openURL:url];
}

5、label設(shè)置刪除線

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;

6、 設(shè)置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];

7、 NSArray倒序

NSArray *arr = [NSArray array];

NSArray *tmparr = [[arr reverseObjectEnumerator] allObjects];

NSLog(@"%@",tmparr);

8、UIImageView設(shè)置圓角時產(chǎn)生UI不流暢的解決

//        只需要加上這段代碼就可以去除鋸齒
imageView.layer.shouldRasterize = YES;
當shouldRasterize設(shè)成true時,layer被渲染成一個bitmap,并緩存起來,等下次使用時不會再重新去渲染了。實現(xiàn)圓角本身就是在做顏色混合(blending),如果每次頁面出來時都blending,消耗太大,這時shouldRasterize = yes,下次就只是簡單的從渲染引擎的cache里讀取那張bitmap,節(jié)約系統(tǒng)資源。

額外收獲:如果在滾動tableView時,每次都執(zhí)行圓角設(shè)置,肯定會阻塞UI,設(shè)置這個將會使滑動更加流暢。
原文鏈接:http://blog.csdn.net/zhuangyou123/article/details/8737367

9、 打電話

//1、這種發(fā)放,撥打完電話回不到原來的應(yīng)用,會停留在通訊錄里面,而且是直接撥打,不彈出提示
      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的案例。

10 、不能改變高度的控件,通過設(shè)置transform來更改高度

  //比如UIProgressView:
self.progressView.transform=CGAffineTransformMakeScale(1.0F,3.0F);

11 、顯示和隱藏隱藏文件

終端輸入:
1、顯示

//        defaults write com.apple.finder AppleShowAllFiles -bool true

2、  隱藏

//        defaults write com.apple.finder AppleShowAllFiles -bool false

#pragma mark - 11 多國文字

http://blog.sina.com.cn/s/blog_7b9d64af0101jncz.html

12、 設(shè)置UITextView,UITextField KVC的運用

//UITextView,UITextField設(shè)置文字長度
[self.textView setValue:@140 forKey:@"limit"];
[self.textFiled setValue:@14 forKey:@"limit"];
需要引入https://github.com/xuwening/textInputLimit

//UITextField placeHolder設(shè)置
[self.textFieldsetValue:[UIColorredColor]forKeyPath:@"_placeholderLabel.textColor"];
[self.textFieldsetValue:[UIFontsystemFontOfSize:14]forKeyPath:@"_placeholderLabel.font"];

13、 cell 系統(tǒng)分割線距離邊框設(shè)置

 cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 0);

歡迎補充

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容