YYSegmentViewController 分頁控制器的介紹

github地址:https://github.com/SwimBoys/YYSegmentViewController

一豪娜、頁面介紹

  1. YYSegmentConfig:配置文件
  2. YYSegmentViewController:控制器
  3. YYContainerScrollView:控制器view底部的ScrollView
  4. YYControllerPageView:控制器view的容器
  5. YYSegmentedView:上邊title的底部view
  6. YYSegmentItemView:裝title和指示器的view
  7. YYIndicatorView:指示器view

二、添加控制器方法

??? 1. 直接添加控制器的view

let config = YYSegmentConfig()
let vc = YYSegmentViewController(config)
self.addChild(vc)
vc.view.frame = CGRect(x: 0, y: 130, width: view.bounds.size.width, height: 600)
self.view.addSubview(vc.view)

注意事項(xiàng):一定要添加 self.addChild(vc),并且在初始化完成之后就得添加

??? 2. 繼承 YYSegmentViewController

image.png

注意事項(xiàng):在 viewDidLoad() 方法中,在調(diào)用 super.viewDidLoad() 方法之前設(shè)置 config

三、使用技巧

??? 1. 設(shè)置 Title

oneVc.tabBarItem.title = "第一章"

如果想改變 Title杀迹,可直接設(shè)置 tabBarItem.title

??? 2. 設(shè)置角標(biāo)

oneVc.tabBarItem.badgeValue = "112"

如果想改變角標(biāo),可直接設(shè)置 tabBarItem.badgeValue

??? 3. 指示器

當(dāng)設(shè)置 itemIndicatorViewShapeStyle 類型為橢圓和橫桿時(shí),itemIndicatorViewWidthChangeStyle不再起作用崭别,默認(rèn)為橫桿

??? 4. 頁面刷新

當(dāng)子view是普通view,想刷新整個(gè)頁面時(shí)恐锣,最底層 YYContainerScrollView 是ScrollView茅主,可添加刷新控件,當(dāng)子view是 tableView 時(shí)土榴,可設(shè)置刷新方式诀姚,整個(gè)刷新還是列表刷新

vc.containerScrView.mj_header = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(refreshControlAction))

當(dāng)設(shè)置了headerView時(shí),需要多一個(gè)設(shè)置玷禽,高度為 headerView 的高度

vc.containerScrView.mj_header.ignoredScrollViewContentInsetTop = 300

??? 5. 自定義指示器

指示器view為 YYIndicatorView赫段,可進(jìn)行自定義,示例代碼如下

vc.initDone = { [weak self] in
    guard let this = self else {return}
    let indicatorViewContentView = this.vc.segmentCtlView.indicatorView.contentView
    let mixIndicatorView = MixIndicatorView(frame: indicatorViewContentView.bounds)
    indicatorViewContentView.addSubview(mixIndicatorView)
    mixIndicatorView.autoresizingMask = [.flexibleWidth,.flexibleHeight]
}

config.itemIndicatorViewShapeStyle = .background(color: UIColor.clear, img: nil)

class MixIndicatorView: UIView {
    let ellipseView = UIView()
    let crossBarView = UIView()
    override init(frame: CGRect) {
        super.init(frame: frame)
        ellipseView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.8)
        ellipseView.frame = CGRect.init(x: 0, y: 0, width: bounds.width, height: 20)
        ellipseView.center = CGPoint.init(x: bounds.width/2, y: bounds.height/2)
        ellipseView.layer.cornerRadius = 10
        ellipseView.autoresizingMask = [.flexibleWidth,.flexibleTopMargin,.flexibleBottomMargin]
        addSubview(ellipseView)

        let crossBarViewHight:CGFloat = 3
        crossBarView.backgroundColor = UIColor.red
        crossBarView.frame = CGRect.init(x: 0, y: bounds.height - crossBarViewHight, width: bounds.width, height: crossBarViewHight)
        addSubview(crossBarView)
        crossBarView.autoresizingMask = [.flexibleWidth,.flexibleTopMargin,.flexibleBottomMargin]
    }
    
    public required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
組合樣式

三论衍、使用示例

oneVc.tabBarItem.title = "第一章"
twoVc.tabBarItem.title = "第二章"
oneVc.tabBarItem.badgeValue = "112"

let headerV = UIImageView(frame: CGRect.init(x: 0, y: 0, width: UIScreen.main.bounds.width, height: 300))
headerV.image = UIImage(named: "longzhu")
headerV.contentMode = .scaleAspectFill
headerV.backgroundColor = UIColor.red
        
let config = YYSegmentConfig()
config.containerControllerArr = [oneVc, twoVc]
let width = view.bounds.size.width / 2
config.segmentBackgroundColor = .yellow
config.headView = headerV
config.itemSpacing = 10
config.itemTitleSelectedScale = 1.5
config.itemWidthStyle = .equalToTitleWidth(margin: 0)
config.segmentControlHeight = 100
config.itemIndicatorViewBackgroundColor = UIColor.blue
config.itemBadgeStyle = .round
config.itemBadgeTitleColor = .blue
config.itemBadgeValueLabelOffset = CGPoint(x: 0, y: -5)
config.itemViewSegmentSelectedStyle = .gradient
config.itemBadgeSize = CGSize(width: 10, height: 10)
config.refreshType = .container
config.segmentControlPositionType = .top
config.itemIndicatorViewWidthChangeStyle = .stationary(baseWidth: width)
config.itemIndicatorViewShapeStyle = .crossBar(widthChangeStyle: .equalToItemWidth(margin: 0), height: 6)
config.isShowItemSeparatorLineView = true
config.itemSeparatorLineTopBottomMargin = (5, 5)
config.itemBadgeTitleFont = 9
    
let vc = YYSegmentViewController(config)
self.addChild(vc)
vc.view.frame = CGRect(x: 0, y: 130, width: view.bounds.size.width, height: 600)
self.view.addSubview(vc.view)
vc.containerScrView.mj_header = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(refreshControlAction))vc.containerScrView.mj_header.ignoredScrollViewContentInsetTop = 300
vc.segmentCtlView.clickAnimation = false
vc.pageView.isScrollEnabled = false
vc.segmentCtlView.delegate = self
vc.scrollViewDragTopOffsetYBlock = { (scr, offsetY) in

}
vc.initDone = { 

}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末瑞佩,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子坯台,更是在濱河造成了極大的恐慌炬丸,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,402評(píng)論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件蜒蕾,死亡現(xiàn)場(chǎng)離奇詭異稠炬,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)咪啡,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評(píng)論 3 392
  • 文/潘曉璐 我一進(jìn)店門首启,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人撤摸,你說我怎么就攤上這事毅桃“伲” “怎么了?”我有些...
    開封第一講書人閱讀 162,483評(píng)論 0 353
  • 文/不壞的土叔 我叫張陵钥飞,是天一觀的道長莺掠。 經(jīng)常有香客問我,道長读宙,這世上最難降的妖魔是什么彻秆? 我笑而不...
    開封第一講書人閱讀 58,165評(píng)論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮结闸,結(jié)果婚禮上唇兑,老公的妹妹穿的比我還像新娘。我一直安慰自己桦锄,他們只是感情好扎附,可當(dāng)我...
    茶點(diǎn)故事閱讀 67,176評(píng)論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著结耀,像睡著了一般帕棉。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上饼记,一...
    開封第一講書人閱讀 51,146評(píng)論 1 297
  • 那天,我揣著相機(jī)與錄音慰枕,去河邊找鬼具则。 笑死,一個(gè)胖子當(dāng)著我的面吹牛具帮,可吹牛的內(nèi)容都是我干的博肋。 我是一名探鬼主播,決...
    沈念sama閱讀 40,032評(píng)論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼蜂厅,長吁一口氣:“原來是場(chǎng)噩夢(mèng)啊……” “哼匪凡!你這毒婦竟也來了?” 一聲冷哼從身側(cè)響起掘猿,我...
    開封第一講書人閱讀 38,896評(píng)論 0 274
  • 序言:老撾萬榮一對(duì)情侶失蹤病游,失蹤者是張志新(化名)和其女友劉穎,沒想到半個(gè)月后稠通,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體衬衬,經(jīng)...
    沈念sama閱讀 45,311評(píng)論 1 310
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 37,536評(píng)論 2 332
  • 正文 我和宋清朗相戀三年改橘,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了滋尉。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 39,696評(píng)論 1 348
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡飞主,死狀恐怖狮惜,靈堂內(nèi)的尸體忽然破棺而出高诺,到底是詐尸還是另有隱情,我是刑警寧澤碾篡,帶...
    沈念sama閱讀 35,413評(píng)論 5 343
  • 正文 年R本政府宣布虱而,位于F島的核電站,受9級(jí)特大地震影響耽梅,放射性物質(zhì)發(fā)生泄漏薛窥。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,008評(píng)論 3 325
  • 文/蒙蒙 一眼姐、第九天 我趴在偏房一處隱蔽的房頂上張望诅迷。 院中可真熱鬧,春花似錦众旗、人聲如沸罢杉。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評(píng)論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽滩租。三九已至,卻和暖如春利朵,著一層夾襖步出監(jiān)牢的瞬間律想,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評(píng)論 1 269
  • 我被黑心中介騙來泰國打工绍弟, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留技即,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 47,698評(píng)論 2 368
  • 正文 我出身青樓樟遣,卻偏偏與公主長得像而叼,于是被迫代替她去往敵國和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子豹悬,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 44,592評(píng)論 2 353

推薦閱讀更多精彩內(nèi)容