1、首先,我们分析一下为什么要自定义UITabbar?对于这个问题,我们很自然的会说,因为系统的用着不爽呗,而且有各种限制;答案确实如此。在我的印象中,使用系统的Tabbar是iOS开发初学者时候才用的,而随着我们开发经验的增长,(特别是产品经理的需求)我们不得不开始逐步尝试自定义Tabbar拉。我是不是很啰嗦,开始上代码吧,大家都等不及了。github链接
/*原理*/
创建一个UIImageView添加到Tabbar上,然后在UIImageView上添加Button,通过Button的代理实现Tabbar上控制器之间的相互切换。
2、首先我要新建一个继承于UITabBarController的类,作为程序的根视图;

3、接下来,我要自定义一个Button(继承于系统Button的);这里利用枚举值列举了Button的选中和未选中两种状态;代理用来实现点击不同的Button实现页面的切换;+号方法用来初始化Button(这里的Button就是系统Tabbar的按钮)




4、自定义Button完成了,接下来就是怎么在自定义TabbarController中实现的问题了(不多说,看代码)



5.完成了,下面看效果吧。(完成了,有问题欢迎骚扰)

网友评论