1)重寫touchesBegan方法, 點擊屏幕的時候隱藏鍵盤
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch=[[event allTouches] anyObject];
if (touch.tapCount >=1) {
[meter resignFirstResponder];
[feet resignFirstResponder];
}
}git
至關於屏幕任何位置的點擊事件(除了各組件的點擊處)能夠在這個方法裏執行要隱藏或remove的view.github
2)重寫textField的delegate中的-(BOOL)textFieldShouldReturn:(UITextField *)textField方法,在點擊return的時候調用方法,讓textField放棄
sql
第一響應者.數據庫
3)在最底層鋪上一個透明的button活着controller,時間相應爲回收鍵盤.api
3.UINavigationBar的控件設置app
UINavigationBar (導航欄)上的設置主要分兩部分, 爲導航欄上的各類導航部件(UINavigationItem), 爲導航欄的相關設置.navigationBar—導航條,iOS7以後默認是半透明的,iOS7以前默認是不透明的。 navigationBar 豎屏下默認高度44,橫屏下默認高度32。 iOS7以後,navigationBar的背景會延伸到statusBar上。導航欄高度仍保持44,但顯示效果爲64。 每一個視圖控制器都有一個UINavigationItem屬性。UINavigationItem中設置的左按鈕、右按鈕、標題等,會隨着控制器的顯 ,也顯示到NavigationBar上。 iview
self.navigationItem.title = @"老炮兒"; //修改本身試圖的標題ide
self.navigationItem.titleView = ........ //能夠設置標題視圖函數
self.navigationController.navigationBarHidden = NO; // 導航欄的顯隱屬性 工具
self.navigationController.navigationBar.barStyle =UIBarStyleDefault; // 導航欄樣式
self.navigationController.navigationBar.backgroundColor =[UIColor redColor]; // 背景顏色
self.navigationController.navigationBar.barTintColor =[UIColor yellowColor]; // 導航欄顏色
self.navigationController.navigationBar.tintColor =[UIColor blackColor];// 導航欄上的元素顏色(對字體顏色無效)
導航欄半透明的效果(iOS7之後 默認爲 YES),當半透明效果開啓時 屏幕左上角爲座標原點,當關閉時,導航欄左下角爲座標原點 self.navigationController.navigationBar.translucent = NO;
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@"XXX.png"] forBarMetrics:UIBarMetricsDefault];
IOS5.0以上,api有了上面setBackgroundImage的方法,能夠直接設置,若是項目須要適配5.0如下版本的設備,最好加一個判讀,是否有此函數,有則設置,沒有就經過drawRect方法設置。
另外:設置背景圖片沒法匹配backButton或rightButtonItem,因此返回按鈕或右邊自定義的Bar button Item須要自行處理。
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:12.] forKey:NSFontAttributeName]]; //修改字體大小
[self.navigationController.navigationBar setTitleTextAttributes:[NSDictionary dictionaryWithObject:[UIColor redColor] forKey:NSForegroundColorAttributeName]]; //修改字體顏色
self.navigationController.hidesBarsOnSwipe = YES;
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
1)edgesForExtendedLayout
這個屬性是UIExtendedEdge類型,用來制定視圖的哪條邊須要擴展。好比UIRectEdgeTop,它把視圖區域頂部擴展到statusBar(之前是navigationBar下面);UIRectEdgeBottom是把區域底部擴展到屏幕下方邊緣。默認值是UIRectEdgeAll。
2)extendedLayoutIncludesOpaqueBars
若是你使用了不透明的導航欄,設置edgesForExtendedLayout的時候也請將extendedLayoutIncludesOpaqueBars的值設置爲No(默認值是YES)。
3)automaticallyAdjustsScrollViewInsets
爲YES時,它會找view裏的scrollView,並設置scrollView的contentInset爲{64, 0, 0, 0}。在爲YES的時候,UIViewController下若是隻有一個UIScollView或者其子類,那麼會自動留出空白,讓scollview滾動通過各類bar下面時能隱約看到內容。可是每一個UIViewController只能有惟一一個UIScollView或者其子類,若是超過一個,須要將此屬性設置爲NO,本身去控制留白以及座標問題。
[view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"pabb_leftnaviview_bg.png"]]];
大小設置:
[view setFrame:CGRectMake(9, 60, 120, 250)];
相似於圖1,我不想讓下面的那些空顯示。很簡單,添加「self.tableView.tableFooterView = [[UIView alloc] init];」
試過都說好,加完這句以後就變成了圖2的樣子
.
在model類中的.h文件中聲明屬性,以獲取後臺返回數據,名稱,類型相同
在存儲數據時(通常在VC中)
根據後臺返回的數據的數據類型,設置顯示用的cell樣式
根據要cell在的位置,設置要顯示的cell的樣式
navigationBar上的edit按鈕有兩種狀態"edit"和"done",配合tableView使用,可讓tableView進入編輯狀態.如今自定義編輯按鈕
把edit寫成中文樣式
11,UI中各個控件的繼承圖譜
12.Button的字體顯示位置,顏色的設置
設置文字的內容
[btn setTitle: @"search" forState: UIControlStateNormal];
設置字體的大小
btn.titleLabel.font = [UIFont systemFontOfSize: 14.0];
初始化button後的字體顏色是白色的,若是背景顏色也是白色是看不到字的,須要修改button的字體顏色
[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
有些時候咱們想讓UIButton的title居左對齊,咱們設置
btn.textLabel.textAlignment = UITextAlignmentLeft; ××××××是沒有做用的,咱們須要設置
btn.contentHorizontalAlignment = UIControlContentHorizonAlignmentLeft; //左對齊
可是問題又出來,此時文字會緊貼到作邊框,咱們能夠設置
btn.contentEdgeInsets = UIEdgeInsetsMake(0,10, 0, 0); //使文字距離作邊框保持10個像素的距離。
13.當鋪設UI控件時,可能會遇到層級遮擋的關係View1,View2的父試圖都是View,若是View2 擋住了View1,可是View1有touch事件.
咱們能夠用如下代碼寫到View2的類中
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hitView = [super hitTest:point withEvent:event];
if (hitView == self)
{
return nil;
}
else
{
return hitView;
}}
//獲取拼音首字母(傳入漢字字符串, 返回大寫拼音首字母)
-(NSString *)firstCharactor
{
//轉成了可變字符串
NSMutableString *str = [NSMutableString stringWithString:self.name];
//先轉換爲帶聲調的拼音
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformMandarinLatin,NO);
//再轉換爲不帶聲調的拼音
CFStringTransform((CFMutableStringRef)str,NULL, kCFStringTransformStripDiacritics,NO);
//轉化爲大寫拼音
NSString *pinYin = [str capitalizedString];
//獲取並返回首字母
return [pinYin substringToIndex:1];
}
15,寫一個經常使用的獲取當前日期,時間的代碼。而且能以規定的格式顯示出來
NSDate *currentDate = [NSDate date];
//獲取當前時間,日期
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@
"YYYY/MM/dd hh:mm:ss SS"
];
NSString *dateString = [dateFormatter stringFromDate:currentDate];
NSLog(@
"dateString:%@"
,dateString);
這樣就能按照規定的格式顯示日期,時間了。
dateString:2015/01/03 08:01:20 24
說明下格式對應的意義
YYYY(年)/MM(月)/dd(日) hh(時):mm(分):ss(秒) SS(毫秒)須要用哪一個的話就把哪一個格式加上去。值得注意的是,若是想顯示兩位數的年份的話,能夠用」YY/MM/dd hh:mm:ss SS」,兩個Y表明兩位數的年份。並且大寫的M和小寫的m表明的意思也不同。「M」表明月份,「m」代碼分鐘「HH」表明24小時制,「hh」表明12小時制
16,CoreData數據遷移步驟
//數據遷移步驟
//保證原有的數據庫不要作任何改動
//1,選中model.xcdatamodeld -> 工具欄Editor -> add Model Version
//2,爲新版本取個名字 -> Next
//3,右面菜單欄說明文件下 Model Version -> 選擇新建立的版本
//4,爲新的表添加新的字段
//5,刪除原來的model類4個文件
//6,Command + N -> NSManagerObjectSubClass -> 選中新的表 -> creat
//7,Command + N -> mapping model ->選中原來的模型 ->選中新模型 ->建立
//8, 給建立的小祕書提示版本遷移 [store addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:[NSURL fileURLWithPath:sqllitePath] options:@{NSMigratePersistentStoresAutomaticallyOption:@YES,NSInferMappingModelAutomaticallyOption:@YES} error:nil];
17,UITextField的placeholder的字體,顏色,居中顯示
UITextField *textField = [[UITextField alloc]initWithFrame:CGRectMake(12,10, SCREEN_WIDTH - 24, 50)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.placeholder = @"請輸入標題";
[textField setValue:[UIColor redColor] forKeyPath:@"_placeholderLabel.textColor"];
[textField setValue:[UIFont boldSystemFontOfSize:18] forKeyPath:@"_placeholderLabel.font"];
textField.textAlignment = NSTextAlignmentCenter;
18,計時器
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(onTime) userInfo:nil repeats:YES];
在SEL中執行去執行須要延遲操做的方法,好比動畫,好比自動消失效果,好比循環播放
19,全球流NSNotificationCenter的用法
第一步:註冊通知中心
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(pushVC:) name:@"fuck" object:nil];
第二步:寫SEL的方法,傳遞的參數是字典類型的
-(void)pushVC:(NSNotification *)user{
NSDictionary *dic = user.userInfo; //屬性,提取出字典
CustomFileTableViewController *customVC = [[CustomFileTableViewController alloc]init];
customVC.folderTime = [dic valueForKey:@"folderTime"];
customVC.folderName = [dic valueForKey:@"folderName"];
[self.navigationController pushViewController:customVC animated:YES];
}
第三步:在須要相應方法的地方對暗號
-(void)goHome:(UIButton *)button{
NSArray *array = button.subviews;
UITextField *textField = (UITextField *)[array objectAtIndex:0];
NSString *folderName = textField.text;
UILabel *label = (UILabel *)[array objectAtIndex:1];
NSString *folderTime = label.text;
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithCapacity:0];
[dic setObject:folderName forKey:@"folderName"];
[dic setObject:folderTime forKey:@"folderTime"];
[[NSNotificationCenter defaultCenter] postNotificationName:@"fuck" object:button userInfo:dic]; //對上暗號並將須要傳遞的信息,寫入字典傳遞過去
}
20,
int ABS(int i); // 處理int類型的取絕對值
double fabs(double i); //處理double類型的取絕對值
float fabsf(float i); /處理float類型的取絕對值
21,建立單例類方法,經過這個類方法建立出來的都是單例的類對象
使用了Category(類目),即便在你不知道一個類的源碼狀況下,向這個類添加擴展的方法。因爲繼承NSObject,全部的類均可以使用
在.h中
//使用可變字典存儲每一個類的單一實例,鍵爲類名,值爲該類的對象;
//聲明爲靜態變量,能夠保存上次的值;
static NSMutableDictionary *instanceDict;
id instance;
+ (instancetype)sharedInstance {
@synchronized(self)
{
//初始化字典;
if (instanceDict == nil) {
instanceDict = [[NSMutableDictionary alloc] init];
}
//獲取類名;
NSString *className = NSStringFromClass([self class]);
if (className) {
//查找字典中該類的對象,使用類名去進行查找,能夠確保一個類只被存儲一次;
instance = instanceDict[className];
if (instance == nil) {
//該類的對象還沒實例化,就進行初始化,並根據鍵值對的形式存儲;
instance = [[self.class alloc] init];
[instanceDict setValue:instance forKey:className];
}else{
//該類對象已經存儲在字典中,直接返回instance便可;
}
}else{
//沒有獲取類名,因此確保sharedInstance是一個類方法,用類進行調用;
}
return instance;
}
}
@end
經過類方法:sharedInstance,建立出來的對象,都是單例.
22,iOS 8 系統自帶BlurEffect 毛玻璃特效
毛玻璃 的UI 設計在手機開發中已經 很是熱門,在以前的 開發中 通常用到 github上FXBlurView 封裝好的一個view類 ,能夠直接應用加載到控件中,iOS 8 後更新的
UIBlurEffect類和 UIVisualEffectView類使這種特效應用更加便捷,高效。
使用也很是簡便,UIBlurEffect 類是設定毛玻璃特效的類型,UIVisualEffectView類在建立時加入上一個類對象,剩下的跟普通的view 控件等用法就同樣了 ,附代碼事例:
// 建立須要的毛玻璃特效類型
UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleLight];
// 毛玻璃view 視圖
UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect];
//添加到要有毛玻璃特效的控件中
effectView.frame = self.imageV.bounds;
[self.imageV addSubview:effectView];
//設置模糊透明度
effectView.alpha = .8f;
首先本身定義一個NSCharacterSet, 包含須要去除的特殊符號
NSCharacterSet *set = [NSCharacterSet characterSetWithCharactersInString:@"@/:;()¥「」"、[]{}#%-*+=_\\|~<>$€^•'@#$%^&*()_+'\""];
因爲NSString中有全角符號和半角符號, 所以有些符號要包括全角和半角的
而後調用stringByTrimmingCharactersInSet
NSString *trimmedString = [string stringByTrimmingCharactersInSet:set];
trimmedString就是過濾後的字符串
取出字符串中的空格
http://my.oschina.net/u/2361492/blog/487703?fromerr=pgTCOpmI
關於NSCharacterSet的一些深層次的簡介
使用 selectRowAtIndexPath,不會有反應
換一個 scrollToRowAtIndexPath 以後果真能夠了。
[TableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:NO];
25.如何讓UITableView響應touchesBegan:withEvent:之類的UIResponder的方法
UITableView是不會響應touchesBegan:withEvent:之類的UIResponder的方法的。所以,加在其上的全部視 圖的響應者鏈就斷了。若是在UITableView其上加任何的自身不具有相似UIButton同樣有目標動做機制的UIView及其子類控件的時候,這 個控件也不會響應touchesBegan:withEvent:方法。即使是設置該控件的userInteractionEnabled爲YES也沒用。如此一來,若是想要這些控件具備交互性能怎麼辦?有一種很直觀的方法,給這個控件加上手勢識別器
27.改變textfiled的placeholder的字體顏色大小