从一个界面跳到下一个界面,这个功能不难实现,But:根据UI给的设计图,下一个界面需要更改返回按钮的样式只有一个< 这样的返回按钮,UI这样设计的话,系统自带的返回就不能用了,在开发过程中作为一个有经验的开发者,都会自己去自定义一些东西,当然了,有相应的第三方类库就更好了,但各种各样的问题也会出现,由于代码不是自己写的,所以修改起来也比较头疼
言归正传:
问题描述:
最近一个项目中运用到了搜索的功能其中需要跳到搜索列表页面有热门搜索词展示,这一块儿我运用到了第三方PYSearchViewController这个封装的控件,主要任务就是在搜索热词界面上面搜索框左边添加 一个返回按钮 <
问题解决方案:
UIButton* BackBT = ({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[buttonsetImage:[UIImage imageNamed:@"icon_Lift"] forState:UIControlStateNormal];
[buttonaddTarget:self action:@selector(searchButtonBack) forControlEvents:UIControlEventTouchUpInside];
button.frame=CGRectMake(0,0,40.0f,40.0f);
button;
});
UIView*leftCustomView = [[UIViewalloc]initWithFrame:BackBT.frame];
[leftCustomViewaddSubview:BackBT];
_searchViewController.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftCustomView];
这个代码运主要的作用是自定义navigationItem.leftBarButtonItem,其他的地方也是通用的
然而你会发现问题并没有解决项目运行以后,你会发现左边的按钮有是有了,但按钮的大小和中间搜索框的位置和大小会有问题,怎么修改也改不掉,这时需要在PYSearchViewController.m 文件中找到 adaptWidth = adaptWidth + navigationBarLayoutMargins.left+ navigationBarLayoutMargins.right 这行代码,可以根据自己的需求加些宽度就可以了,一般40.0f 就可以了,这时再跑下程序OK 完美解决问题
欢迎入驻Ios 技术交流群 811548343
网友评论