1.nav1.navigationBar.barStyle=UIBarStyleBlack;
//改變導(dǎo)航欄背景顏色系統(tǒng)模式(背景黑色,標題白色);
2.1延時1.2秒執(zhí)行方法
[self performSelector:@selector(gotoBack) withObject:nil afterDelay:1.2];
2. //設(shè)置選項欄項選中和不選中狀態(tài)下的兩張圖片
nav1.tabBarItem.image= [[UIImageimageNamed:@"tabbar_mainframe@2x.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
nav1.tabBarItem.selectedImage= [[UIImageimageNamed:@"tabbar_mainframeHL@2x.png"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//設(shè)置選項欄項文字選中和不選中的顯示狀態(tài)(顏色或是大小)
[nav1.tabBarItemsetTitleTextAttributes:dicforState:UIControlStateNormal];
[nav1.tabBarItemsetTitleTextAttributes:selectDicforState:UIControlStateSelected];
//設(shè)置選中tabBar選中后圖片的顏色額
[self.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];
//設(shè)置tabBar樣式
[self.tabBarsetBarStyle:UIBarStyleBlack];
//設(shè)置按鈕跳轉(zhuǎn)到tabBar的任意一個view
self.tabBarController.selectedViewController=self.tabBarController.viewControllers[1];
3.//導(dǎo)航欄左右按鈕圖片和文字的顏色(系統(tǒng)自己的圖片和文字)
self.navigationController.navigationBar.tintColor= [UIColorwhiteColor];
//UIBarMetricsDefault豎屏格式高度:44
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"navigationbar.png"]forBarMetrics:UIBarMetricsDefault];
//UIBarMetricsCompact橫屏樣式高度:32
[self.navigationController.navigationBarsetBackgroundImage:[UIImageimageNamed:@"nav-32.png"]forBarMetrics:UIBarMetricsCompact];
4.//調(diào)導(dǎo)航欄標題的的顏色和大小
[self.navigationController.navigationBarsetTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:18],NSForegroundColorAttributeName:[UIColorblueColor]}];
5.//導(dǎo)航頁面的跳轉(zhuǎn)
[self.navigationControllerpushViewController:sevenanimated:YES];
[self.navigationControllerpopToRootViewControllerAnimated:YES];
//self.navigationController.viewControllers找到push過去的頁面挥下,并放到數(shù)組里面
NSArray*viewController =self.navigationController.viewControllers;
[self.navigationControllerpopToViewController:viewController[2]animated:YES];
#pragma mark -按鈕的點擊事件
- (void)buttonClick:(UIButton*)button{
//返回任意某一頁
//[first, second, third, fourth, fifth]
//[0,1,2,3,4]
//self.navigationController.viewControllers找到push過去的頁面,并放到數(shù)組里面
NSArray*viewController =self.navigationController.viewControllers;
[self.navigationControllerpopToViewController:viewController[2]animated:YES];
}
6.UINavigation導(dǎo)航
(1)UINavigationBar導(dǎo)航條(2)UINavigationItem導(dǎo)航欄內(nèi)容
//第一個是共用的設(shè)置一個與它非平行界面(就是說用UITabBarController-tabBar.viewControllers=@[nav1,nav2,nav3,nav4];這個加上去的導(dǎo)航欄是平行關(guān)系互不影響)第二個是單獨設(shè)置每個界面
8.//隱藏系統(tǒng)自帶的返回按鈕,如果設(shè)置左按鈕桨醋,系統(tǒng)自帶的返回按鈕會被覆蓋掉
// [self.navigationItem setHidesBackButton:YES];
9. //整體全局更改title的文字和顏色和大小
NSDictionary*dic =@{NSForegroundColorAttributeName: [UIColorredColor],NSFontAttributeName: [UIFontsystemFontOfSize:17.0]};
[[UINavigationBarappearance]setTitleTextAttributes:dic];
10.UIToolBar工具條
//UIToolBar是導(dǎo)航控制器默認隱藏的工具條
//設(shè)置UIToolBar的隱藏狀態(tài)
11.//圖片渲染,圖片旋轉(zhuǎn)
imageView.transform=CGAffineTransformRotate(imageView.transform, rotation.rotation);
12.UITableView (表視圖)
self.automaticallyAdjustsScrollViewInsets=NO;//每個視圖都必須先加這個關(guān)閉自動布局
//UITableViewCell
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
[cell addSubview:lab(imageView……)]直接在行cell任何位置上直接添加上文字或圖片
//從復(fù)用池里面查找
UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:iden];
//UITableViewCellSelectionStyleNone無選中效果
cell.selectionStyle=UITableViewCellSelectionStyleDefault;
//設(shè)置標題頭文字
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{
//設(shè)置標題尾文字
- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section{
//設(shè)置行高:cell的高度:默認44
- (CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{
//設(shè)置標題頭的高度
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{
//設(shè)置標題尾的高度
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section{
//cell的選中事件
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
//取消選中效果
[tableViewdeselectRowAtIndexPath:indexPathanimated:YES];
}
//自定義標題頭
- (UIView*)tableView:(UITableView*)tableView viewForHeaderInSection:(NSInteger)section{
//自定義標題尾
- (UIView*)tableView:(UITableView*)tableView viewForFooterInSection:(NSInteger)section{
13./*************UIView-層次關(guān)系***************/
//添加視圖:addSubview
[self.viewaddSubview:view5];
//移除視圖:removeFromSuperview
//[view5 removeFromSuperview];
//將某個視圖移動到最上面bringSubviewToFront:
[self.viewbringSubviewToFront:view1];
//將某個視圖移動到最下面sendSubviewToBack:
[self.viewsendSubviewToBack:view1];
//將某一個視圖移動到另一個視圖的上面
[self.viewinsertSubview:view1aboveSubview:view3];
//將某一個視圖移動到另一個視圖的下面
[self.viewinsertSubview:view1belowSubview:view2];
//將某個視圖放到指定的位置
//[self.view insertSubview:view1 atIndex:3];
//交換兩個視圖的位置
[self.viewexchangeSubviewAtIndex:1withSubviewAtIndex:4];
14.
//label添加的按鈕想要展示的話需要將clipsToBounds=Y(jié)ES
//UIView的屬性:是否切割多余視圖的屬性
label.clipsToBounds=YES;
//只有當(dāng)clipsToBounds=Y(jié)ES時棚瘟,label的圓角效果才能出來
label.layer.cornerRadius=20;
//userInteractionEnabled打開用戶響應(yīng)開關(guān)的屬性當(dāng)為YES時:可以參與用戶響應(yīng)
只有UILabel和UIImageView默認NO
//只有父視圖能夠接受用戶響應(yīng),它上面的子視圖才能參與用戶響應(yīng)
label.userInteractionEnabled=YES;
15.View的設(shè)置
//變形屬性是以中心點為基準的
//變形屬性:transform
//大小變形:CGAffineTransformMakeScalewidth*sxheigth*sy
viewTransform.transform=CGAffineTransformMakeScale(10,0.5);
//角度變形:CGAffineTransformMakeRotation
viewTransform.transform=CGAffineTransformMakeRotation(0);//角度實現(xiàn),大小變形就不會被實現(xiàn)了后面覆蓋前面的
//NSStringFromCGPoint將CGPoint類型轉(zhuǎn)成字符串類型
NSLog(@"%@",NSStringFromCGPoint(viewTransform.center));
//圓角設(shè)置:layer
//圓角大小:cornerRadius正方形邊長的一半為圓
viewLayer.layer.cornerRadius=30;
//邊框設(shè)置:borderWidth
viewLayer.layer.borderWidth=5;
//設(shè)置邊框顏色:borderColor默認黑色[UIColor greenColor].CGColor
viewLayer.layer.borderColor= [UIColorgreenColor].CGColor;
viewLayer.layer.borderColor= [[UIColorgreenColor]CGColor];
//是否切割子視圖超出圓角的部分:YES:切割掉默認NO:不切割
//如果masksToBounds=Y(jié)ES陰影效果出不來
viewLayer.layer.masksToBounds=NO;
//陰影
//陰影的透明度:shadowOpacity默認0.0
viewLayer.layer.shadowOpacity=1.0;
//陰影的偏移量:shadowOffset
viewLayer.layer.shadowOffset=CGSizeMake(50,50);
//陰影的顏色:shadowColor
viewLayer.layer.shadowColor= [UIColorblueColor].CGColor;
//陰影角度:shadowRadius帶有虛化的效果
viewLayer.layer.shadowRadius=30;
16.動畫設(shè)置
//獲取圖片路徑:相對路徑
//第一個參數(shù):文件的名字
//第二個參數(shù):文件的類型
NSString*path = [[NSBundlemainBundle]pathForResource:@"map"ofType:@"png"];
UIImage*imagePath = [UIImageimageWithContentsOfFile:path];
UIImageView*imageViewPath = [[UIImageViewalloc]initWithFrame:CGRectMake(20,130,200,50)];
imageViewPath.image= imagePath;
/****動畫效果相關(guān)屬性****/
//創(chuàng)建圖片數(shù)組
//開辟內(nèi)存空間
NSMutableArray*array = [[NSMutableArrayalloc]initWithCapacity:0];
for(inti =1; i <=12; i ++) {
[arrayaddObject:[UIImageimageNamed:[NSStringstringWithFormat:@"player%d.png",i]]];
}
//設(shè)置動畫圖片喜最,需要接收一個數(shù)組偎蘸,數(shù)組里面的類型必須是UIImage類型
imageView.animationImages= array;
//動畫時間:數(shù)組里面所有的圖片轉(zhuǎn)一圈所用時間
imageView.animationDuration=1;
//循環(huán)次數(shù):大于0的數(shù):寫幾就循環(huán)幾次,結(jié)束0:無限循環(huán)
imageView.animationRepeatCount=0;
//開始動畫
[imageViewstartAnimating];
//按鈕點擊開始或結(jié)束
staticBOOLisAnimation =YES;//static靜態(tài)變量用過立即釋放
if(isAnimation)
{//等價于isAnimation為真(isAnimation==YES)
[imageViewstopAnimating];
isAnimation =NO;
//這時的isAnimation=YES被釋放為空,接著
//賦值為NO再次點擊按鈕時isAnimation=NO;
}
else
{
[imageViewstartAnimating];
isAnimation =YES;
}
//定時器
[NSTimerscheduledTimerWithTimeInterval:0.2target:selfselector:@selector(birdFly:)userInfo:nilrepeats:YES];
17.
#pragma mark -編輯按鈕的方法
//如何更改UITableView的編輯狀態(tài)
//_tableView.editing默認NO
//設(shè)置UITableView的編輯狀態(tài)
[_tableViewsetEditing:!_tableView.editinganimated:YES];
//只有UITableView處于可編輯狀態(tài)時,才能進行刪除迷雪、移動等操作
//NO->YES->NO
#pragma mark -刷新按鈕的方法
- (void)refreshButtonClick:(UIBarButtonItem*)button
//刷新數(shù)據(jù)
//reloadData會把UITableView所有的代理方法都會重新執(zhí)行一次
[_tableViewreloadData];
//更改刪除文字
- (NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath{
return@"刪除";
}
//設(shè)置UITableView的編輯類型
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
if(indexPath.section==0) {
//返回刪除類型
returnUITableViewCellEditingStyleDelete;
}
//返回新增元素類型
returnUITableViewCellEditingStyleInsert;
}
//單選刪除及插入元素對應(yīng)的方法
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath{
//有關(guān)刪除元素的方法實現(xiàn)
if(editingStyle ==UITableViewCellEditingStyleDelete) {
//<1>更改數(shù)據(jù)源
[[_dataArrayobjectAtIndex:indexPath.section]removeObjectAtIndex:indexPath.row];
//<2>刪除對應(yīng)多余的cell
[_tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationAutomatic];
}
//有關(guān)新增元素的方法實現(xiàn)
if(editingStyle ==UITableViewCellEditingStyleInsert) {
//<1>更改數(shù)據(jù)源
PersonModel*model = [[PersonModelalloc]init];
model.name=@"我是新來的";
[[_dataArrayobjectAtIndex:indexPath.section]insertObject:modelatIndex:indexPath.row];
//<2>新增一行的cell
[_tableViewinsertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
}
}
#pragma mark -有關(guān)移動元素的方法
- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath{
//sourceIndexPath原始數(shù)據(jù)
//destinationIndexPath結(jié)果的數(shù)據(jù)
//<1>保存將要移動的那行cell上面的數(shù)據(jù)
PersonModel*model = [[_dataArrayobjectAtIndex:sourceIndexPath.section]objectAtIndex:sourceIndexPath.row];
//<2>從原始位置上刪除
[[_dataArrayobjectAtIndex:sourceIndexPath.section]removeObject:model];
//<3>放到新的位置上
[[_dataArrayobjectAtIndex:destinationIndexPath.section]insertObject:modelatIndex:destinationIndexPath.row];
[_tableViewreloadData];
}
18.
#pragma mark -系統(tǒng)的編輯按鈕的方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated{
[supersetEditing:editinganimated:animated];
//editingNO->YES->NO
//設(shè)置UITableView的編輯狀態(tài)
[_tableViewsetEditing:editinganimated:YES];//==[_tableView setEditing:!_tableView.editing animated:YES]
[_tableViewsetEditing:editinganimated:YES];
//清空之前選擇的元素
[_rubbishArrayremoveAllObjects];************
if(editing) {
[self.navigationItemsetRightBarButtonItem:_rubbishButtonanimated:YES];
}else{
[self.navigationItemsetRightBarButtonItem:nilanimated:YES];
}
}
#pragma mark -一鍵刪除的按鈕的方法
- (void)rubbishButtonClick:(UIBarButtonItem*)button{
//清除選中的待刪除的數(shù)據(jù)
[_dataArrayremoveObjectsInArray:_rubbishArray];
//tableView刷新數(shù)據(jù)
[_tableViewreloadData];
#pragma mark -多選刪除的相關(guān)方法
//設(shè)置編輯類型
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{
//如果刪除和插入同時返回限书,就會出現(xiàn)多選刪除
returnUITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;
}
//多選刪除對應(yīng)的方法實現(xiàn)
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{
//當(dāng)tableView處于編輯狀態(tài)時
if(tableView.editing) {
//將選中的那行cell上面的數(shù)據(jù)放到將要刪除的數(shù)組里面
[_rubbishArrayaddObject:[_dataArrayobjectAtIndex:indexPath.row]];
}else{
//當(dāng)tableView處于不可編輯狀態(tài)時,愛干嘛干嘛
NSLog(@"hhhh");
}
}
//cell的反選
- (void)tableView:(UITableView*)tableView didDeselectRowAtIndexPath:(NSIndexPath*)indexPath{
if(tableView.editing) {
[_rubbishArrayremoveObject:[_dataArrayobjectAtIndex:indexPath.row]];
}
}
19.搜索
//搜索框
@property(nonatomic,strong)UISearchBar*searchBar;
//搜索控制器
@property(nonatomic,strong)UISearchDisplayController*sdc;
//<5>UISearchBar
//搜索框的大姓逻帧:全屏的寬*44
//把搜索框放到tableView上面
_tableView.tableHeaderView=_searchBar;
//<6>UISearchDisplayController搜索控制器
//搜索控制器在實例化時會將搜索框與本個控制器關(guān)聯(lián)起來
_sdc= [[UISearchDisplayControlleralloc]initWithSearchBar:_searchBarcontentsController:self];
//UISearchDisplayController本身就存在一個UITableView倦西,這個UITableView也是需要遵守協(xié)議和代理,這個tableView只有一段,如果執(zhí)行這個代理方法的tableView不是我們自己手動創(chuàng)建的慧邮,那么他就是UISearchDisplayController管理的那一個tableView并且每個UITableView的代理方法都要判斷是不是手動創(chuàng)建的那個if(tableView !=_tableView)
//UISearchDisplayController管理的UITableView的協(xié)議代理
_sdc.searchResultsDataSource=self;
_sdc.searchResultsDelegate=self;
//UISearchDisplayController本身又有一個delegate,需要遵守本身的代理方法UISearchDisplayDelegate
_sdc.delegate=self;
if(tableView !=_tableView) {
cell.textLabel.text=_resultArray[indexPath.row];
}else{
cell.textLabel.text=_dataArray[indexPath.section][indexPath.row];
#pragma mark - UISearchDisplayDelegate
//當(dāng)輸入框里面的文字出現(xiàn)改變就執(zhí)行
- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString{
//清空之前的搜索結(jié)果
[_resultArrayremoveAllObjects];
//searchString輸入框里面的文字
for(NSArray*arrin_dataArray) {
for(NSString*strinarr) {
//查找
NSRangerange = [strrangeOfString:searchString];
if(range.length!=0) {
[_resultArrayaddObject:str];
}
}
}
returnYES;
}
20.索引
//設(shè)置索引文字顏色:默認藍色
_tableView.sectionIndexColor= [UIColorredColor];
//設(shè)置索引背景條的顏色:默認透明
_tableView.sectionIndexBackgroundColor= [UIColorgrayColor];
//設(shè)置點擊索引時背景條的顏色:默認透明
_tableView.sectionIndexTrackingBackgroundColor= [UIColorcyanColor];
#pragma mark -索引相關(guān)方法
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView{
NSMutableArray*array = [[NSMutableArrayalloc]initWithCapacity:0];
//搜索小圖標
[arrayaddObject:UITableViewIndexSearch];
for(inti ='a'; i <='z'; i ++) {
[arrayaddObject:[NSStringstringWithFormat:@"%c",i]];
}
returnarray;
}
- (NSInteger)tableView:(UITableView*)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index{
//index索引的下標
//index能對應(yīng)到tableView的段
if(index ==0) {
NSLog(@"search");
}
returnindex -1;
}
21.瀑布流
#pragma mark - UIScrollViewDelegate
- (void)scrollViewDidScroll:(UIScrollView*)scrollView{
if(scrollView ==_aTableView) {
_bTableView.contentOffset=_aTableView.contentOffset;
_cTableView.contentOffset=_aTableView.contentOffset;
}elseif(scrollView ==_bTableView){
_aTableView.contentOffset=_bTableView.contentOffset;
_cTableView.contentOffset=_bTableView.contentOffset;
}else{
_aTableView.contentOffset=_cTableView.contentOffset;
_bTableView.contentOffset=_cTableView.contentOffset;
}
}
_bTableView.showsVerticalScrollIndicator=NO;隱藏垂直方向的滾動條
22.解析plist文件Day12;
//找到文件的路徑
NSString*path = [[NSBundlemainBundle]pathForResource:@"bookData"ofType:@"plist"];
//plist文件是個數(shù)組,里面是字典
//不可變數(shù)組接收plist文件
NSArray*array = [NSArrayarrayWithContentsOfFile:path];
for(NSDictionary*dicinarray) {
BookModel*model = [[BookModelalloc]initWithDic:dic];//這個方法在分類里直接調(diào)用如下
/************************************************************************************/
- (instancetype)initWithDic:(NSDictionary*)dic
{
if(self=[superinit]) {
[selfsetValuesForKeysWithDictionary:dic];
}
returnself;
}
/************************************************************************************/
[_dataArrayaddObject:model];
}
23.系統(tǒng)的Cell上添加控件
if(cell ==nil) {
cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:iden];
}
//需要添加else判斷,把cell上面的控件清除否則會出現(xiàn)覆蓋的情況
else{
//cell.contentView.subviews將cell上面所有的控件放到數(shù)組里面
while([cell.contentView.subviewslastObject] !=nil) {
//將最后一個元素移除除去;刪除Cell上的控件而不是cell清空
[(UIView*)[cell.contentView.subviewslastObject]removeFromSuperview];
}
}
//將控件添加到cell上面
[cell.contentViewaddSubview:titleLable];
24.自定義Cell上添加控件
//init方法
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString*)reuseIdentifier{
self= [superinitWithStyle:stylereuseIdentifier:reuseIdentifier];
if(self) {
//調(diào)用creatUI方法
[selfcreatUI];
}
returnself;
}
- (void)creatUI{
}
//內(nèi)部封裝的方法
- (void)textAndImage:(BookModel*)model{
_titleLabel.text= model.title;
_detailLabel.text= model.detail;
_priceLabel.text= model.price;
_iconImageView.image= [UIImageimageNamed:model.icon];
}
25.注冊cell不能接收代理傳過來的值
//注冊cell類:xib類型
[_tableViewregisterNib:[UINibnibWithNibName:@"MyTableViewCell"bundle:nil]forCellReuseIdentifier:@"iden"];
//UITableViewCell的寫法
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
{
MyTableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:@"iden"forIndexPath:indexPath];
BookModel*model =_dataArray[indexPath.row];
cell.titleLabel.text= model.title;
returncell;
}
26.手勢Day08
//點擊手勢
UITapGestureRecognizer*tap
//移動手勢
UIPanGestureRecognizer*pan
//添加到視圖上面
[imageViewaddGestureRecognizer:pan];
#pragma mark -移動手勢的方法
- (void)pan:(UIPanGestureRecognizer*)pan{
//手勢的生命:began - changed - ended
//判斷手勢的狀態(tài):state
if(pan.state==UIGestureRecognizerStateBegan|| pan.state==UIGestureRecognizerStateChanged) {
//1调限、找到手勢所在的view
UIImageView*imageView = (UIImageView*)pan.view;
//2、獲取手勢移動的位移
CGPointpoint = [pantranslationInView:self.view];
//3误澳、更改imageView的位置
imageView.center=CGPointMake(imageView.center.x+ point.x, imageView.center.y+ point.y);
//4耻矮、手勢的位移是會疊加的,需要把手勢移動的位移歸零
//CGPointZero == CGPointMake(0,0)
[pansetTranslation:CGPointZeroinView:self.view];
}
}
//縮放手勢
UIPinchGestureRecognizer*pinch
//旋轉(zhuǎn)手勢
UIRotationGestureRecognizer*rotation
27,動畫,視頻,音頻Day08TomCat
28. scrollView,UIPageControlDay09
//更改UIScrollView的偏移量
[UIViewanimateWithDuration:0.5animations:^{
scrollView.contentOffset=CGPointMake(self.view.frame.size.width* i,0);
}];
29.UITextView
//特有屬性
//是否可以滾動
textView.scrollEnabled=YES;
//隱藏滑塊
textView.showsVerticalScrollIndicator=NO;
//是否鏈接網(wǎng)址忆谓、電話裆装、日期、地址
textView.dataDetectorTypes=UIDataDetectorTypeAll;
30.
//這個方法可以改變TableViewCell的背景顏色
cell.contentView.backgroundColor= [UIColorbrownColor];
31.
//刪除多余的Cell
[_tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];
32.永久性傳值
1.存值
//NSUserDefaults用于永久性存值的一種方式;
//整個工程有且只有一個NSUserDefaults模式:單例plist格式
//NSUserDefaults:key對應(yīng)valuekey:字符串樣式value:NSString倡缠、NSArray哨免、NSDictionary、NSData昙沦、NSDate琢唾、NSURL、NSNumber盾饮、BOOL
//NSUserDefaults實例化
NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];
//添加文件
[usersetObject:textField.textforKey:@"value"];
//執(zhí)行寫入plist的操作采桃,進行實時更新
[usersynchronize];
2.取值
//NSUserDefaults實例化
NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];
//獲取對應(yīng)key里面的值
NSString*str = [userobjectForKey:@"value"];
3.刪除整體
//NSUserDefaults實例化
NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults]
//移除文件
[userremoveObjectForKey:@"value"];
//執(zhí)行寫入plist的操作,進行實時更新
[usersynchronize];
4.刪除單個元素
//用來接收的數(shù)組,先刪除想要去除的元素,再重新存入(相當(dāng)于把原來存入的值給覆蓋了)
[_dataArrayremoveObjectAtIndex:indexPath.row];
NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];
[usersetObject:_dataArrayforKey:@"user"];
[usersynchronize];
33.
_textField.text.intValue將字符串轉(zhuǎn)成int數(shù)字類型;
34.//刪除父視圖上這個類型的所有元素
//將父視圖上的所有元素加到一個數(shù)組里面進行遍歷
for(UIView*viewinself.view.subviews) {
//從父視圖上,判斷是不是這個類型的元素
if([viewisKindOfClass:[UICollectionViewCellclass]]) {
//如果是則從父視圖上刪除
[viewremoveFromSuperview];
}
}
35.json解析的時間轉(zhuǎn)換為當(dāng)前的時間
NSString*s =@"1445416710";
NSDate*d = [NSDatedateWithTimeIntervalSince1970:[sfloatValue]];
NSDateFormatter*dateformatter=[[NSDateFormatteralloc]init];
[dateformattersetDateFormat:@"yyyy年MM月dd日HH:mm:ss"];
NSString* dateStr=[dateformatterstringFromDate:d];
NSLog(@"%@",dateStr);
36.Unicode轉(zhuǎn)成標準漢字
直接調(diào)用方法
- (NSString*)replaceUnicode:(NSString*)unicodeStr
{
NSString*tempStr1 = [unicodeStrstringByReplacingOccurrencesOfString:@"\\u"withString:@"\\U"];
NSString*tempStr2 = [tempStr1stringByReplacingOccurrencesOfString:@"\""withString:@"\\\""];
NSString*tempStr3 = [[@"\""stringByAppendingString:tempStr2]
stringByAppendingString:@"\""];
NSData*tempData = [tempStr3dataUsingEncoding:NSUTF8StringEncoding];
NSString* returnStr = [NSPropertyListSerializationpropertyListFromData:tempDatamutabilityOption:NSPropertyListImmutableformat:NULLerrorDescription:NULL];
NSLog(@"%@",returnStr);
return[returnStrstringByReplacingOccurrencesOfString:@"\\r\\n"withString:@"\n"];
}
37.tableView的cell滑動,顯示置頂,刪除,或者收藏
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *toTop = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"置頂" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"置頂");
[tableView setEditing:NO animated:YES];
}];
toTop.backgroundColor =[UIColor redColor];
UITableViewRowAction *delege = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"刪除");
[tableView setEditing:NO animated:YES];
}];
delege.backgroundColor =[UIColor greenColor];
NSArray *arrar = [NSArray arrayWithObjects:toTop,delege, nil];
return arrar;
}
38.tableView的編輯狀態(tài)下全選,修改每個cell左側(cè)的選擇按鈕的背景圖片 http://www.cocoachina.com/bbs/read.php?tid=248799
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell * cell = [self.tableView cellForRowAtIndexPath:indexPath];
NSLog(@"%@",cell.subviews);//先看看它的子視圖,發(fā)現(xiàn)只有一個子視圖丘损,叫"
UIView * view1 = cell.subviews[0];
NSLog(@"%@",view1.subviews);/*然后這里你看到它有3個子視圖普办,分別是
">",
"; layer = >",
">"
你一個是你點擊了cell之后cell背景變成淡藍色的背景view,第二個是cell里面常用的contentView徘钥,cell的textLabel就是放在這里面的衔蹲,第三個就是我們要找的,其實這些都是摸索的呈础,我是把第三個view取到舆驶,然后把它顏色設(shè)成紅色,你就會看到那個藍色的圖標就在這個紅色區(qū)域里猪落,所以可以確定藍色圖標是這個view的子視圖贞远,所以從這里繼續(xù)想下取*/
UIView * CellEditControl = view1.subviews[2];//按輸出順序來,就是這樣向下查找笨忌,知道找到你想要的那個view
UIImageView * imgView = [[[[cell.subviews[0] subviews] objectAtIndex:2] subviews] objectAtIndex:0];
UIImageView * testImgView = [[UIImageView alloc]initWithImage:imgView.image];
testImgView.frame = CGRectMake(60, 0, 30, 25);
[cell.contentView addSubview:testImgView];
39.鍵盤頂端顏色,文字的修改
textField2.attributedPlaceholder=[[NSAttributedStringalloc]initWithString:[[TitleUtilitysharedInstance]getTitleWithKey:@"Password"]attributes:@{NSForegroundColorAttributeName: color}];
40.獲取view的名字
[NSStringstringWithUTF8String:object_getClassName(smallView)
41.刪除navgationBar最下面的黑色分割線(UIImageView)
UIImageView*imgV = [self.navigationController.navigationBar.subviews[0]subviews][0];
imgV.hidden=YES;
42.cell右邊標志符的顏色改變
self.accessoryType = UITableViewCellAccessoryCheckmark;
self.tintColor = [UIColor colorWithRed:140.0/255.0 green:197.0/255.0blue:66.0/255.0alpha:1];
42.slider滑塊固定大小分段滑動
/************分段滑動的方法*****************/
//// These number values represent each slider position
//numbers = @[@(500), @(1000), @(1500), @(2000), @(2600)];
//// slider values go from 0 to the number of values in your numbers array
//NSInteger numberOfSteps = ((float)[numbers count] - 1);
//slider.maximumValue = numberOfSteps;
//slider.minimumValue = 0;
//
//// As the slider moves it will continously call the -valueChanged:
//slider.continuous = NO; // NO makes it call only once you let go
//[slider addTarget:self
//action:@selector(valueChanged:)
//forControlEvents:UIControlEventValueChanged];
//}
//- (void)valueChanged:(UISlider *)sender {
//// round the slider position to the nearest index of the numbers array
//NSUInteger index = (NSUInteger)(slider.value + 0.5);
//[slider setValue:index animated:YES];
//NSNumber *number = numbers[index]; // <-- This numeric value you want
//NSLog(@"sliderIndex: %i", (int)index);
//NSLog(@"number: %@", number);
//}
/************分段滑動的方法*****************/
43.cell高度自適應(yīng)
CGSizelabel2Size = [[_dataDicobjectForKey:@"skill"]boundingRectWithSize:sizeoptions:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingUsesFontLeading)attributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:14.0],NSForegroundColorAttributeName:[UIColorblackColor]}context:nil].size;
CGRectframe = [stringboundingRectWithSize:CGSizeMake(WIDTH-15,CGFLOAT_MAX)options:NSStringDrawingUsesLineFragmentOriginattributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:17]}context:nil];
44.cell單個刷新
//一個section刷新
NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:2];
[tableview reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
//一個cell刷新
NSIndexPath *indexPath=[NSIndexPath indexPathForRow:3 inSection:0];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil] withRowAnimation:UITableViewRowAnimationNone];
45.繪制虛線
+ (void)drawDashLine:(UIView*)lineView lineLength:(int)lineLength lineSpacing:(int)lineSpacing lineColor:(UIColor*)lineColor
{
CAShapeLayer*shapeLayer = [CAShapeLayerlayer];
[shapeLayersetBounds:lineView.bounds];
[shapeLayersetPosition:CGPointMake(CGRectGetWidth(lineView.frame) /2,CGRectGetHeight(lineView.frame))];
[shapeLayersetFillColor:[UIColorclearColor].CGColor];
//設(shè)置虛線顏色為blackColor
[shapeLayersetStrokeColor:lineColor.CGColor];
//設(shè)置虛線寬度
[shapeLayersetLineWidth:CGRectGetHeight(lineView.frame)];
[shapeLayersetLineJoin:kCALineJoinRound];
//設(shè)置線寬蓝仲,線間距
[shapeLayersetLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:lineLength], [NSNumbernumberWithInt:lineSpacing],nil]];
//設(shè)置路徑
CGMutablePathRefpath =CGPathCreateMutable();
CGPathMoveToPoint(path,NULL,0,0);
CGPathAddLineToPoint(path,NULL,CGRectGetWidth(lineView.frame),0);
[shapeLayersetPath:path];
CGPathRelease(path);
//把繪制好的虛線添加上來
[lineView.layeraddSublayer:shapeLayer];
}
46.文字復(fù)制到粘帖版
UIPasteboard*pasteboard = [UIPasteboardgeneralPasteboard];
pasteboard.string=@“要復(fù)制的文字”;
46.文字做富文本
//做富文本
NSMutableAttributedString*attributedText2 =[[NSMutableAttributedStringalloc]initWithString:_weightLab.textattributes:@{NSForegroundColorAttributeName: [UIColorgrayColor]}];
//range為只更改你選中的區(qū)域
[attributedText2setAttributes:@{NSForegroundColorAttributeName: [UIColorblackColor]}range:NSMakeRange(0,2)];
_weightLab.attributedText= attributedText2;
[selfaddSubview:_weightLab];
46.cell改變選中顏色背景圖片分割線的顏色
1.系統(tǒng)默認的顏色設(shè)置
//無色
cell.selectionStyle?=?UITableViewCellSelectionStyleNone;
//藍色
cell.selectionStyle?=?UITableViewCellSelectionStyleBlue;
//灰色
cell.selectionStyle?=?UITableViewCellSelectionStyleGray;
2.自定義顏色和背景設(shè)置
3.改變UITableViewCell選中時背景色:
UIColor?*color?=?[[UIColoralloc]initWithRed:0.0green:0.0blue:0.0alpha:1];//通過RGB來定義自己的顏色
cell.selectedBackgroundView?=?[[[UIView?alloc]?initWithFrame:cell.frame]?autorelease];
cell.selectedBackgroundView.backgroundColor?=?[UIColor?xxxxxx];
3.自定義UITableViewCell選中時背景
cell.selectedBackgroundView?=?[[[UIImageView?alloc]?initWithImage:[UIImage?imageNamed:@"cellart.png"]]?autorelease];
還有字體顏色
cell.textLabel.highlightedTextColor?=?[UIColor?xxxcolor];?[cell.textLabel?setTextColor:color]
4.設(shè)置tableViewCell間的分割線的顏色
[theTableView?setSeparatorColor:[UIColor?xxxx?]];
47.collection的cell重排編組
//長按手勢
_longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:selfaction:@selector(lonePressMoving:)];
[self.xtCollectionViewaddGestureRecognizer:_longPress];
- (void)lonePressMoving:(UILongPressGestureRecognizer *)longPress
{
switch(_longPress.state) {
caseUIGestureRecognizerStateBegan: {
{
NSIndexPath*selectIndexPath = [self.xtCollectionViewindexPathForItemAtPoint:[_longPress locationInView:self.xtCollectionView]];
//找到當(dāng)前的cell
XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionViewcellForItemAtIndexPath:selectIndexPath];
//定義cell的時候btn是隱藏的,在這里設(shè)置為NO
[cell.btnDeletesetHidden:NO];
[_xtCollectionView beginInteractiveMovementForItemAtIndexPath:selectIndexPath];
}
break;
}
caseUIGestureRecognizerStateChanged: {
[self.xtCollectionViewupdateInteractiveMovementTargetPosition:[longPress locationInView:_longPress.view]];
break;
}
caseUIGestureRecognizerStateEnded: {
[self.xtCollectionViewendInteractiveMovement];
break;
}
default: [self.xtCollectionViewcancelInteractiveMovement];
break;
}
}
- (void)collectionView:(UICollectionView *)collectionView moveItemAtIndexPath:(nonnull NSIndexPath *)sourceIndexPath toIndexPath:(nonnull NSIndexPath *)destinationIndexPath
{
NSIndexPath *selectIndexPath = [self.xtCollectionView indexPathForItemAtPoint:[_longPress locationInView:self.xtCollectionView]];
//找到當(dāng)前的cell
XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionView cellForItemAtIndexPath:selectIndexPath];
[cell.btnDelete setHidden:YES];
[self.array exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];
[self.xtCollectionView reloadData];
}
48.設(shè)置啟動頁的時間
[NSThread sleepForTimeInterval:3.0];//設(shè)置啟動頁面時間
49.數(shù)字用逗號隔開每3位
+(NSString*)countNumAndChangeformat:(NSString*)num
{
intcount =0;
longlonginta = num.longLongValue;
while(a !=0)
{
count++;
a /=10;
}
NSMutableString*string = [NSMutableStringstringWithString:num];
NSMutableString*newstring = [NSMutableStringstring];
while(count >3) {
count -=3;
NSRangerang =NSMakeRange(string.length-3,3);
NSString*str = [stringsubstringWithRange:rang];
[newstringinsertString:stratIndex:0];
[newstringinsertString:@","atIndex:0];
[stringdeleteCharactersInRange:rang];
}
[newstringinsertString:stringatIndex:0];
returnnewstring;
}
50.修改searchBar取消按鈕的文字和顏色
- (void)searchBarTextDidBeginEditing:(UISearchBar*)searchBar{
searchBar.showsCancelButton=YES;
NSLog(@"%@",[searchBarsubviews]);
[(UIButton*)searchBar.subviews[0]setTintColor:[UIColorwhiteColor]];
for(UIView*viewin[[[searchBarsubviews]objectAtIndex:0]subviews]) {
if([viewisKindOfClass:[NSClassFromString(@"UINavigationButton")class]]) {
NSLog(@"%@",view.subviews);
UIButton* cancel =(UIButton*)view;
[cancelsetTitle:[[TitleUtilitysharedInstance]getTitleWithKey:@"alertCancel"]forState:UIControlStateNormal];
}
}
}
51.程序自動關(guān)閉
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2*NSEC_PER_SEC)),dispatch_get_main_queue(), ^{
[theViewremoveFromSuperview];
exit(0);
});
52.數(shù)組元素按字母排序
_enStateArr= [_stateDicallKeys];
_enStateArr= [_enStateArrsortedArrayUsingComparator:^NSComparisonResult(idobj1,idobj2){
NSComparisonResultresult = [obj1compare:obj2];
returnresult==NSOrderedDescending;
}];
53.控件的晃動
#import?
-(void)loadShakeAnimationForView:(UIView*)view
{
CALayer*lbl?=?[viewlayer];
CGPoint?posLbl?=?[lblposition];
CGPoint?y?=?CGPointMake(posLbl.x-10,?posLbl.y);
CGPoint?x?=?CGPointMake(posLbl.x+10,?posLbl.y);
CABasicAnimation*?animation?=?[CABasicAnimationanimationWithKeyPath:@"position"];
[animationsetTimingFunction:[CAMediaTimingFunction
functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[animationsetFromValue:[NSValuevalueWithCGPoint:x]];
[animationsetToValue:[NSValuevalueWithCGPoint:y]];
[animationsetAutoreverses:YES];
[animationsetDuration:0.08];
[animationsetRepeatCount:3];
[lbladdAnimation:animationforKey:nil];
}
54.判斷字符串中是否包含某個字符
//判斷字符是否包含某字符串;
NSString*string =@"hello,shenzhen,martin";
//字條串是否包含有某字符串
if([string rangeOfString:@"martin"].location ==NSNotFound) {
NSLog(@"string不存在martin");
}else{
NSLog(@"string包含martin");
}
//字條串開始包含有某字符串
if([string hasPrefix:@"hello"]) {
NSLog(@"string包含hello");
}else{
NSLog(@"string不存在hello");
}
//字符串末尾有某字符串;
if([string hasSuffix:@"martin"]) {
NSLog(@"string包含martin");
}else{
NSLog(@"string不存在martin");
}
在iOS8以后袱结,還可以用下面的方法來判斷是否包含某字符串:
//在iOS8中你可以這樣判斷
NSString*str =@"hello world";
if([str containsString:@"world"]) {
NSLog(@"str包含world");
}else{
NSLog(@"str不存在world");
}
50.//去掉返回手勢
//去掉返回按鈕
self.navigationItem.leftBarButtonItem= [[UIBarButtonItemalloc]initWithTitle:@""style:(UIBarButtonItemStyleDone)target:selfaction:nil];
//去掉返回手勢
if([self.navigationControllerrespondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled=NO;
}
51.字典轉(zhuǎn)換成字符串
- (NSString*)parseParams:(NSDictionary*)params{
NSString*keyValueFormat;
NSMutableString*result = [NSMutableStringnew];
NSMutableArray*array = [NSMutableArraynew];
//實例化一個key枚舉器用來存放dictionary的key
NSEnumerator*keyEnum = [paramskeyEnumerator];
idkey;
inti=0;
while(key = [keyEnumnextObject]) {
if(i==0) {
keyValueFormat = [NSStringstringWithFormat:@"%@=%@",key,[paramsvalueForKey:key]];
}else
{
keyValueFormat = [NSStringstringWithFormat:@"&%@=%@",key,[paramsvalueForKey:key]];
}
//NSLog(@"%@",keyValueFormat);
[resultappendString:keyValueFormat];
[arrayaddObject:keyValueFormat];
i++;
}
returnresult;
}
52.按鈕文字居左
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;這行代碼亮隙,把按鈕的內(nèi)容(控件)
的對齊方式修改為水平左對齊,但是這們會緊緊靠著左邊垢夹,不好看溢吻,
所以我們還可以修改屬性:
button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
這行代碼可以讓按鈕的內(nèi)容(控件)距離左邊10個像素,這樣就好看多了
53.Xcode8內(nèi)部自動集成了VVDocumenter
Xcode8注釋快捷鍵為option+command+/
54.四舍五入
-(float)roundFloat:(float)price{
return(floorf(price*100+0.5))/100;
}
55.兩個時間比較大小
/************
日期格式請傳入:2013-08-05 12:12:12果元;如果修改日期格式促王,比如:2013-08-05,則將[df setDateFormat:@"yyyy-MM-dd HH:mm:ss"];修改為[df setDateFormat:@"yyyy-MM-dd"];
***********/
+(int)compareDate:(NSString*)date01 withDate:(NSString*)date02{
intci;
NSDateFormatter*df = [[NSDateFormatteralloc]init];
[dfsetDateFormat:@"yyyy-MM-dd HH:mm:ss"];
NSDate*dt1 = [[NSDatealloc]init];
NSDate*dt2 = [[NSDatealloc]init];
dt1 = [dfdateFromString:date01];
dt2 = [dfdateFromString:date02];
NSComparisonResultresult = [dt1compare:dt2];
switch(result)
{
//date02比date01大
caseNSOrderedAscending: ci=1;break;
//date02比date01小
caseNSOrderedDescending: ci=-1;break;
//date02=date01
caseNSOrderedSame: ci=0;break;
default:NSLog(@"erorr dates %@, %@", dt2, dt1);break;
}
returnci;
}
56.修改輸入框提示文字的顏色
UIColor *color = [UIColor whiteColor];
userNameTextField.attributedPlaceholder = [[NSAttributedString alloc]
initWithString:@"請輸入手機號"
attributes:@{NSForegroundColorAttributeName : color}];