今天看到一篇總結(jié)開(kāi)發(fā)經(jīng)驗(yàn)的文章偶翅,看了幾條發(fā)現(xiàn)一些很有用廉侧,準(zhǔn)備記錄一下把認(rèn)為比較通用需要的進(jìn)行再總結(jié)(原地址):
1.view截圖
UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0.0);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
2.view設(shè)置圓角
#define ViewBorderRadius(View, Radius, Width, Color)\
\
[View.layer setCornerRadius:(Radius)];\
[View.layer setMasksToBounds:YES];\
[View.layer setBorderWidth:(Width)];\
[View.layer setBorderColor:[Color CGColor]] // view圓角
3.各種系統(tǒng)文件目錄獲取
//獲取temp(存放臨時(shí)文件请毛,iTunes不會(huì)備份和恢復(fù)此目錄,此目錄下文件可能會(huì)在應(yīng)用退出后刪除)
#define PathTemp NSTemporaryDirectory()
//獲取Document(應(yīng)用中用戶數(shù)據(jù)可以放在這里,iTunes備份和恢復(fù)的時(shí)候會(huì)包括此目錄)
#define PathDocument [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
//獲取Cache(存放緩存文件,iTunes不會(huì)備份此目錄胳喷,此目錄下文件不會(huì)在應(yīng)用退出刪除)
#define PathCache [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
4.導(dǎo)入自定義字體庫(kù)
---
1、找到你想用的字體的 ttf 格式夭织,拖入工程
2吭露、在工程的plist中增加一行數(shù)組,“Fonts provided by application”
3尊惰、為這個(gè)key添加一個(gè)item讲竿,value為你剛才導(dǎo)入的ttf文件名
4、直接使用即可:label.font = [UIFont fontWithName:@"你剛才導(dǎo)入的ttf文件名" size:20.0]弄屡;
---
5.在非ViewController的地方彈出UIAlertController對(duì)話框
// 最好抽成一個(gè)分類
UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"Title" message:@"message" preferredStyle:UIAlertControllerStyleAlert];
//...
id rootViewController = [UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController = ((UINavigationController *)rootViewController).viewControllers.firstObject;
}
if([rootViewController isKindOfClass:[UITabBarController class]])
{
rootViewController = ((UITabBarController *)rootViewController).selectedViewController;
}
[rootViewController presentViewController:alertController animated:YES completion:nil];
6.在狀態(tài)欄增加網(wǎng)絡(luò)請(qǐng)求的菊花题禀,類似safari加載網(wǎng)頁(yè)的時(shí)候狀態(tài)欄菊花
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
7.關(guān)于tableview刪除一行
他給的方法是
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
// 如果是你需要隱藏的那一行,返回高度為0
if(indexPath.row == YouWantToHideRow)
return 0;
return 44;
}
// 然后再你需要隱藏cell的時(shí)候調(diào)用
[self.tableView beginUpdates];
[self.tableView endUpdates];
但是我覺(jué)得一般應(yīng)用場(chǎng)景刪除是要把tableview的數(shù)組中的數(shù)據(jù)刪除膀捷,我之前在做帶關(guān)聯(lián)的問(wèn)卷中有用到tableview的cell的添加和刪除迈嘹,是這樣寫的
//刪除一行動(dòng)畫
- (void)tableViewDeleteCellWithIndexPath:(NSIndexPath *)indexPath
{
[_tableView beginUpdates];
[_tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[_tableView endUpdates];
}
//添加一行動(dòng)畫
- (void)tableViewInsertCellWithIndexPath:(NSIndexPath *)indexPath
{
[_tableView beginUpdates];
[_tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[_tableView endUpdates];
}