ios 工作总结的一些常用难记的点

1.nav1.navigationBar.barStyle=UIBarStyleBlack;

//改变导航栏背景颜色系统模式(背景黑色,标题白色);

2.1延时1.2秒执行方法

[self performSelector:@selector(gotoBack) withObject:nil afterDelay:1.2];

2. //设置选项栏项选中和不选中状态下的两张图片

nav1.tabBarItem.image= [[UIImageimageNamed:@"[email protected]"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

nav1.tabBarItem.selectedImage= [[UIImageimageNamed:@"[email protected]"]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];

//设置选项栏项文字选中和不选中的显示状态(颜色或是大小)

[nav1.tabBarItemsetTitleTextAttributes:dicforState:UIControlStateNormal];

[nav1.tabBarItemsetTitleTextAttributes:selectDicforState:UIControlStateSelected];

//设置选中tabBar选中后图片的颜色额

[self.tabBarsetSelectedImageTintColor:[UIColorwhiteColor]];

//设置tabBar样式

[self.tabBarsetBarStyle:UIBarStyleBlack];

//设置按钮跳转到tabBar的任意一个view

self.tabBarController.selectedViewController=self.tabBarController.viewControllers[1];

3.//导航栏左右按钮图片和文字的颜色(系统自己的图片和文字)

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.//调导航栏标题的的颜色和大小

[self.navigationController.navigationBarsetTitleTextAttributes:@{NSFontAttributeName:[UIFontsystemFontOfSize:18],NSForegroundColorAttributeName:[UIColorblueColor]}];

5.//导航页面的跳转

[self.navigationControllerpushViewController:sevenanimated:YES];

[self.navigationControllerpopToRootViewControllerAnimated:YES];

//self.navigationController.viewControllers找到push过去的页面,并放到数组里面

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过去的页面,并放到数组里面

NSArray*viewController =self.navigationController.viewControllers;

[self.navigationControllerpopToViewController:viewController[2]animated:YES];

}

6.UINavigation导航

(1)UINavigationBar导航条(2)UINavigationItem导航栏内容

//第一个是共用的设置一个与它非平行界面(就是说用UITabBarController-tabBar.viewControllers=@[nav1,nav2,nav3,nav4];这个加上去的导航栏是平行关系互不影响)第二个是单独设置每个界面

8.//隐藏系统自带的返回按钮,如果设置左按钮,系统自带的返回按钮会被覆盖掉

// [self.navigationItem setHidesBackButton:YES];

9. //整体全局更改title的文字和颜色和大小

NSDictionary*dic =@{NSForegroundColorAttributeName: [UIColorredColor],NSFontAttributeName: [UIFontsystemFontOfSize:17.0]};

[[UINavigationBarappearance]setTitleTextAttributes:dic];

10.UIToolBar工具条

//UIToolBar是导航控制器默认隐藏的工具条

//设置UIToolBar的隐藏状态

11.//图片渲染,图片旋转

imageView.transform=CGAffineTransformRotate(imageView.transform, rotation.rotation);

12.UITableView (表视图)

self.automaticallyAdjustsScrollViewInsets=NO;//每个视图都必须先加这个关闭自动布局

//UITableViewCell

- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{

[cell addSubview:lab(imageView……)]直接在行cell任何位置上直接添加上文字或图片

//从复用池里面查找

UITableViewCell*cell = [tableViewdequeueReusableCellWithIdentifier:iden];

//UITableViewCellSelectionStyleNone无选中效果

cell.selectionStyle=UITableViewCellSelectionStyleDefault;

//设置标题头文字

- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{

//设置标题尾文字

- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section{

//设置行高:cell的高度:默认44

- (CGFloat)tableView:(UITableView*)tableViewheightForRowAtIndexPath:(NSIndexPath*)indexPath{

//设置标题头的高度

- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section{

//设置标题尾的高度

- (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-层次关系***************/

//添加视图: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=YES

//UIView的属性:是否切割多余视图的属性

label.clipsToBounds=YES;

//只有当clipsToBounds=YES时,label的圆角效果才能出来

label.layer.cornerRadius=20;

//userInteractionEnabled打开用户响应开关的属性当为YES时:可以参与用户响应

只有UILabel和UIImageView默认NO

//只有父视图能够接受用户响应,它上面的子视图才能参与用户响应

label.userInteractionEnabled=YES;

15.View的设置

//变形属性是以中心点为基准的

//变形属性:transform

//大小变形:CGAffineTransformMakeScalewidth*sxheigth*sy

viewTransform.transform=CGAffineTransformMakeScale(10,0.5);

//角度变形:CGAffineTransformMakeRotation

viewTransform.transform=CGAffineTransformMakeRotation(0);//角度实现,大小变形就不会被实现了后面覆盖前面的

//NSStringFromCGPoint将CGPoint类型转成字符串类型

NSLog(@"%@",NSStringFromCGPoint(viewTransform.center));

//圆角设置:layer

//圆角大小:cornerRadius正方形边长的一半为圆

viewLayer.layer.cornerRadius=30;

//边框设置:borderWidth

viewLayer.layer.borderWidth=5;

//设置边框颜色:borderColor默认黑色[UIColor greenColor].CGColor

viewLayer.layer.borderColor= [UIColorgreenColor].CGColor;

viewLayer.layer.borderColor= [[UIColorgreenColor]CGColor];

//是否切割子视图超出圆角的部分:YES:切割掉默认NO:不切割

//如果masksToBounds=YES阴影效果出不来

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.动画设置

//获取图片路径:相对路径

//第一个参数:文件的名字

//第二个参数:文件的类型

NSString*path = [[NSBundlemainBundle]pathForResource:@"map"ofType:@"png"];

UIImage*imagePath = [UIImageimageWithContentsOfFile:path];

UIImageView*imageViewPath = [[UIImageViewalloc]initWithFrame:CGRectMake(20,130,200,50)];

imageViewPath.image= imagePath;

/****动画效果相关属性****/

//创建图片数组

//开辟内存空间

NSMutableArray*array = [[NSMutableArrayalloc]initWithCapacity:0];

for(inti =1; i <=12; i ++) {

[arrayaddObject:[UIImageimageNamed:[NSStringstringWithFormat:@"player%d.png",i]]];

}

//设置动画图片,需要接收一个数组,数组里面的类型必须是UIImage类型

imageView.animationImages= array;

//动画时间:数组里面所有的图片转一圈所用时间

imageView.animationDuration=1;

//循环次数:大于0的数:写几就循环几次,结束0:无限循环

imageView.animationRepeatCount=0;

//开始动画

[imageViewstartAnimating];

//按钮点击开始或结束

staticBOOLisAnimation =YES;//static静态变量用过立即释放

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的编辑状态

//_tableView.editing默认NO

//设置UITableView的编辑状态

[_tableViewsetEditing:!_tableView.editinganimated:YES];

//只有UITableView处于可编辑状态时,才能进行删除、移动等操作

//NO->YES->NO

#pragma mark -刷新按钮的方法

- (void)refreshButtonClick:(UIBarButtonItem*)button

//刷新数据

//reloadData会把UITableView所有的代理方法都会重新执行一次

[_tableViewreloadData];

//更改删除文字

- (NSString*)tableView:(UITableView*)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath*)indexPath{

return@"删除";

}

//设置UITableView的编辑类型

- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{

if(indexPath.section==0) {

//返回删除类型

returnUITableViewCellEditingStyleDelete;

}

//返回新增元素类型

returnUITableViewCellEditingStyleInsert;

}

//单选删除及插入元素对应的方法

- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath{

//有关删除元素的方法实现

if(editingStyle ==UITableViewCellEditingStyleDelete) {

//<1>更改数据源

[[_dataArrayobjectAtIndex:indexPath.section]removeObjectAtIndex:indexPath.row];

//<2>删除对应多余的cell

[_tableViewdeleteRowsAtIndexPaths:[NSArrayarrayWithObjects:indexPath,nil]withRowAnimation:UITableViewRowAnimationAutomatic];

}

//有关新增元素的方法实现

if(editingStyle ==UITableViewCellEditingStyleInsert) {

//<1>更改数据源

PersonModel*model = [[PersonModelalloc]init];

model.name=@"我是新来的";

[[_dataArrayobjectAtIndex:indexPath.section]insertObject:modelatIndex:indexPath.row];

//<2>新增一行的cell

[_tableViewinsertRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

}

}

#pragma mark -有关移动元素的方法

- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath{

//sourceIndexPath原始数据

//destinationIndexPath结果的数据

//<1>保存将要移动的那行cell上面的数据

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 -系统的编辑按钮的方法

- (void)setEditing:(BOOL)editing animated:(BOOL)animated{

[supersetEditing:editinganimated:animated];

//editingNO->YES->NO

//设置UITableView的编辑状态

[_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{

//清除选中的待删除的数据

[_dataArrayremoveObjectsInArray:_rubbishArray];

//tableView刷新数据

[_tableViewreloadData];

#pragma mark -多选删除的相关方法

//设置编辑类型

- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath{

//如果删除和插入同时返回,就会出现多选删除

returnUITableViewCellEditingStyleDelete|UITableViewCellEditingStyleInsert;

}

//多选删除对应的方法实现

- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath{

//当tableView处于编辑状态时

if(tableView.editing) {

//将选中的那行cell上面的数据放到将要删除的数组里面

[_rubbishArrayaddObject:[_dataArrayobjectAtIndex:indexPath.row]];

}else{

//当tableView处于不可编辑状态时,爱干嘛干嘛

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搜索控制器

//搜索控制器在实例化时会将搜索框与本个控制器关联起来

_sdc= [[UISearchDisplayControlleralloc]initWithSearchBar:_searchBarcontentsController:self];

//UISearchDisplayController本身就存在一个UITableView,这个UITableView也是需要遵守协议和代理,这个tableView只有一段,如果执行这个代理方法的tableView不是我们自己手动创建的,那么他就是UISearchDisplayController管理的那一个tableView并且每个UITableView的代理方法都要判断是不是手动创建的那个if(tableView !=_tableView)

//UISearchDisplayController管理的UITableView的协议代理

_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

//当输入框里面的文字出现改变就执行

- (BOOL)searchDisplayController:(UISearchDisplayController*)controller shouldReloadTableForSearchString:(NSString*)searchString{

//清空之前的搜索结果

[_resultArrayremoveAllObjects];

//searchString输入框里面的文字

for(NSArray*arrin_dataArray) {

for(NSString*strinarr) {

//查找

NSRangerange = [strrangeOfString:searchString];

if(range.length!=0) {

[_resultArrayaddObject:str];

}

}

}

returnYES;

}

20.索引

//设置索引文字颜色:默认蓝色

_tableView.sectionIndexColor= [UIColorredColor];

//设置索引背景条的颜色:默认透明

_tableView.sectionIndexBackgroundColor= [UIColorgrayColor];

//设置点击索引时背景条的颜色:默认透明

_tableView.sectionIndexTrackingBackgroundColor= [UIColorcyanColor];

#pragma mark -索引相关方法

- (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能对应到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文件是个数组,里面是字典

//不可变数组接收plist文件

NSArray*array = [NSArrayarrayWithContentsOfFile:path];

for(NSDictionary*dicinarray) {

BookModel*model = [[BookModelalloc]initWithDic:dic];//这个方法在分类里直接调用如下

/************************************************************************************/

- (instancetype)initWithDic:(NSDictionary*)dic

{

if(self=[superinit]) {

[selfsetValuesForKeysWithDictionary:dic];

}

returnself;

}

/************************************************************************************/

[_dataArrayaddObject:model];

}

23.系统的Cell上添加控件

if(cell ==nil) {

cell = [[UITableViewCellalloc]initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:iden];

}

//需要添加else判断,把cell上面的控件清除否则会出现覆盖的情况

else{

//cell.contentView.subviews将cell上面所有的控件放到数组里面

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) {

//调用creatUI方法

[selfcreatUI];

}

returnself;

}

- (void)creatUI{

}

//内部封装的方法

- (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

//判断手势的状态: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

//旋转手势

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;

//是否链接网址、电话、日期、地址

textView.dataDetectorTypes=UIDataDetectorTypeAll;

30.

//这个方法可以改变TableViewCell的背景颜色

cell.contentView.backgroundColor= [UIColorbrownColor];

31.

//删除多余的Cell

[_tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic];

32.永久性传值

1.存值

//NSUserDefaults用于永久性存值的一种方式;

//整个工程有且只有一个NSUserDefaults模式:单例plist格式

//NSUserDefaults:key对应valuekey:字符串样式value:NSString、NSArray、NSDictionary、NSData、NSDate、NSURL、NSNumber、BOOL

//NSUserDefaults实例化

NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];

//添加文件

[usersetObject:textField.textforKey:@"value"];

//执行写入plist的操作,进行实时更新

[usersynchronize];

2.取值

//NSUserDefaults实例化

NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];

//获取对应key里面的值

NSString*str = [userobjectForKey:@"value"];

3.删除整体

//NSUserDefaults实例化

NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults]

//移除文件

[userremoveObjectForKey:@"value"];

//执行写入plist的操作,进行实时更新

[usersynchronize];

4.删除单个元素

//用来接收的数组,先删除想要去除的元素,再重新存入(相当于把原来存入的值给覆盖了)

[_dataArrayremoveObjectAtIndex:indexPath.row];

NSUserDefaults*user = [NSUserDefaultsstandardUserDefaults];

[usersetObject:_dataArrayforKey:@"user"];

[usersynchronize];

33.

_textField.text.intValue将字符串转成int数字类型;

34.//删除父视图上这个类型的所有元素

//将父视图上的所有元素加到一个数组里面进行遍历

for(UIView*viewinself.view.subviews) {

//从父视图上,判断是不是这个类型的元素

if([viewisKindOfClass:[UICollectionViewCellclass]]) {

//如果是则从父视图上删除

[viewremoveFromSuperview];

}

}

35.json解析的时间转换为当前的时间

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转成标准汉字

直接调用方法

- (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的编辑状态下全选,修改每个cell左侧的选择按钮的背景图片 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);//先看看它的子视图,发现只有一个子视图,叫"

UIView * view1 = cell.subviews[0];

NSLog(@"%@",view1.subviews);/*然后这里你看到它有3个子视图,分别是

">",

"; layer = >",

">"

你一个是你点击了cell之后cell背景变成淡蓝色的背景view,第二个是cell里面常用的contentView,cell的textLabel就是放在这里面的,第三个就是我们要找的,其实这些都是摸索的,我是把第三个view取到,然后把它颜色设成红色,你就会看到那个蓝色的图标就在这个红色区域里,所以可以确定蓝色图标是这个view的子视图,所以从这里继续想下取*/

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高度自适应

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

//设置虚线颜色为blackColor

[shapeLayersetStrokeColor:lineColor.CGColor];

//设置虚线宽度

[shapeLayersetLineWidth:CGRectGetHeight(lineView.frame)];

[shapeLayersetLineJoin:kCALineJoinRound];

//设置线宽,线间距

[shapeLayersetLineDashPattern:[NSArrayarrayWithObjects:[NSNumbernumberWithInt:lineLength], [NSNumbernumberWithInt:lineSpacing],nil]];

//设置路径

CGMutablePathRefpath =CGPathCreateMutable();

CGPathMoveToPoint(path,NULL,0,0);

CGPathAddLineToPoint(path,NULL,CGRectGetWidth(lineView.frame),0);

[shapeLayersetPath:path];

CGPathRelease(path);

//把绘制好的虚线添加上来

[lineView.layeraddSublayer:shapeLayer];

}

46.文字复制到粘帖版

UIPasteboard*pasteboard = [UIPasteboardgeneralPasteboard];

pasteboard.string=@“要复制的文字”;

46.文字做富文本

//做富文本

NSMutableAttributedString*attributedText2 =[[NSMutableAttributedStringalloc]initWithString:_weightLab.textattributes:@{NSForegroundColorAttributeName: [UIColorgrayColor]}];

//range为只更改你选中的区域

[attributedText2setAttributes:@{NSForegroundColorAttributeName: [UIColorblackColor]}range:NSMakeRange(0,2)];

_weightLab.attributedText= attributedText2;

[selfaddSubview:_weightLab];

46.cell改变选中颜色背景图片分割线的颜色

1.系统默认的颜色设置

//无色

cell.selectionStyle = UITableViewCellSelectionStyleNone;

//蓝色

cell.selectionStyle = UITableViewCellSelectionStyleBlue;

//灰色

cell.selectionStyle = UITableViewCellSelectionStyleGray;

2.自定义颜色和背景设置

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.设置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]];

//找到当前的cell

XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionViewcellForItemAtIndexPath:selectIndexPath];

//定义cell的时候btn是隐藏的,在这里设置为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]];

//找到当前的cell

XTCollectCell *cell = (XTCollectCell *)[self.xtCollectionView cellForItemAtIndexPath:selectIndexPath];

[cell.btnDelete setHidden:YES];

[self.array exchangeObjectAtIndex:sourceIndexPath.item withObjectAtIndex:destinationIndexPath.item];

[self.xtCollectionView reloadData];

}

48.设置启动页的时间

[NSThread sleepForTimeInterval:3.0];//设置启动页面时间

49.数字用逗号隔开每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.程序自动关闭

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2*NSEC_PER_SEC)),dispatch_get_main_queue(), ^{

[theViewremoveFromSuperview];

exit(0);

});

52.数组元素按字母排序

_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.字典转换成字符串

- (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;这行代码,把按钮的内容(控件)

的对齐方式修改为水平左对齐,但是这们会紧紧靠着左边,不好看,

所以我们还可以修改属性:

button.titleEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);

这行代码可以让按钮的内容(控件)距离左边10个像素,这样就好看多了

53.Xcode8内部自动集成了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}];

你可能感兴趣的:(ios 工作总结的一些常用难记的点)