加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Swift实现类网易云音乐横向scroll menu切换菜单(一)

发布时间:2020-12-14 02:03:49 所属栏目:百科 来源:网络整理
导读:效果图如下: 源代码: https://github.com/uacaps/PageMenu,上图为其中的Demo 5。 本文准备从头开始分析该菜单控件的实现过程,也作为个人的学习笔记。 首先,位于ViewController.swift中viewDidLoad函数中的 self . title = "PAGE MENU" navigationContro
效果图如下:

源代码: https://github.com/uacaps/PageMenu,上图为其中的Demo 5。

本文准备从头开始分析该菜单控件的实现过程,也作为个人的学习笔记。

首先,位于ViewController.swift中viewDidLoad函数中的

self . title = "PAGE MENU"
navigationController ?. navigationBar . titleTextAttributes = [ NSForegroundColorAttributeName : UIColor . whiteColor ()]
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()//这句并没有什么作用

用于配置基础页面的标题内容字体,如上图所示。

var controllerArray : [ UIViewController ] = []

配置用于展示的viewcontroller,如上图中的Favorites Recents Friends Others。

源代码中使用
init (nibName nibNameOrNil: String ?,bundle nibBundleOrNil: NSBundle ?)
对展示的tableview进行初始化。

个人更倾向于配置好storyboardID后采用UIStoryBoard的
func instantiateViewControllerWithIdentifier(identifier: String ) -> UIViewController
对viewcontroller进行配置。


// Initialize scroll menu
pageMenu = CAPSPageMenu (viewControllers: controllerArray,frame: CGRectMake ( 0.0 , view . frame . width ,170)">height ),pageMenuOptions: parameters)
// Optional delegate
pageMenu !. delegate = self
view.addSubview(pageMenu!.view)

之后将配置好的controllerArray送入项目的核心类CAPSPageMenu中,生成pageMenu,使当前viewController接收pageMenu的代理并最后将其添加到当前View中。

下一篇将分析核心类CAPSPageMenu的具体实现。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读