YYSegmentViewController 分页控制器的先容

源代码 2024-9-27 09:07:06 32 0 来自 中国
github地址:https://github.com/SwimBoys/YYSegmentViewController

一、页面先容



  • YYSegmentConfig:设置文件
  • YYSegmentViewController:控制器
  • YYContainerScrollView:控制器view底部的ScrollView
  • YYControllerPageView:控制器view的容器
  • YYSegmentedView:上边title的底部view
  • YYSegmentItemView:装title和指示器的view
  • 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)
注意事项:肯定要添加 self.addChild(vc),而且在初始化完成之后就得添加
    2. 继承 YYSegmentViewController

1.png
注意事项:在 viewDidLoad() 方法中,在调用 super.viewDidLoad() 方法之前设置 config
三、使用本事


    1. 设置 Title

oneVc.tabBarItem.title = "第一章"
如果想改变 Title,可直接设置 tabBarItem.title
    2. 设置角标

oneVc.tabBarItem.badgeValue = "112"
如果想改变角标,可直接设置 tabBarItem.badgeValue
    3. 指示器

当设置 itemIndicatorViewShapeStyle 范例为椭圆和横杆时,itemIndicatorViewWidthChangeStyle不再起作用,默以为横杆
    4. 页面革新

当子view是平凡view,想革新整个页面时,最底层 YYContainerScrollView 是ScrollView,可添加革新控件,当子view是 tableView 时,可设置革新方式,整个革新还是列表革新
vc.containerScrView.mj_header = MJRefreshNormalHeader(refreshingTarget: self, refreshingAction: #selector(refreshControlAction))
当设置了headerView时,须要多一个设置,高度为 headerView 的高度
vc.containerScrView.mj_header.ignoredScrollViewContentInsetTop = 300    5. 自界说指示器

指示器view为 YYIndicatorView,可举行自界说,示例代码如下
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 = .scaleAspectFillheaderV.backgroundColor = UIColor.red        let config = YYSegmentConfig()config.containerControllerArr = [oneVc, twoVc]let width = view.bounds.size.width / 2config.segmentBackgroundColor = .yellowconfig.headView = headerVconfig.itemSpacing = 10config.itemTitleSelectedScale = 1.5config.itemWidthStyle = .equalToTitleWidth(margin: 0)config.segmentControlHeight = 100config.itemIndicatorViewBackgroundColor = UIColor.blueconfig.itemBadgeStyle = .roundconfig.itemBadgeTitleColor = .blueconfig.itemBadgeValueLabelOffset = CGPoint(x: 0, y: -5)config.itemViewSegmentSelectedStyle = .gradientconfig.itemBadgeSize = CGSize(width: 10, height: 10)config.refreshType = .containerconfig.segmentControlPositionType = .topconfig.itemIndicatorViewWidthChangeStyle = .stationary(baseWidth: width)config.itemIndicatorViewShapeStyle = .crossBar(widthChangeStyle: .equalToItemWidth(margin: 0), height: 6)config.isShowItemSeparatorLineView = trueconfig.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 = 300vc.segmentCtlView.clickAnimation = falsevc.pageView.isScrollEnabled = falsevc.segmentCtlView.delegate = selfvc.scrollViewDragTopOffsetYBlock = { (scr, offsetY) in}vc.initDone = { }
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-10-18 18:18, Processed in 0.183292 second(s), 35 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表