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

效果图如下:

代码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 , normal; font-family:'Lantinghei SC'; color:rgb(39, view . frame . width ,170)">height ),pageMenuOptions: parameters)
// Optional delegate
pageMenu !. delegate = self
view.addSubview(pageMenu!.view)

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

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

相关文章

软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...