草庐IT

YYSegmentViewController 分页控制器的介绍

Daniel_you 2023-03-28 原文

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)

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

    2. 继承 YYSegmentViewController

image.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 = .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 = { 

}

有关YYSegmentViewController 分页控制器的介绍的更多相关文章

  1. Ruby Readline 在向上箭头上使控制台崩溃 - 2

    当我在Rails控制台中按向上或向左箭头时,出现此错误:irb(main):001:0>/Users/me/.rvm/gems/ruby-2.0.0-p247/gems/rb-readline-0.4.2/lib/rbreadline.rb:4269:in`blockin_rl_dispatch_subseq':invalidbytesequenceinUTF-8(ArgumentError)我使用rvm来管理我的ruby​​安装。我正在使用=>ruby-2.0.0-p247[x86_64]我使用bundle来管理我的gem,并且我有rb-readline(0.4.2)(人们推荐的最少

  2. ruby-on-rails - 带 Spring 锁的 Rails 4 控制台 - 2

    我正在使用Ruby2.1.1和Rails4.1.0.rc1。当执行railsc时,它被锁定了。使用Ctrl-C停止,我得到以下错误日志:~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`gets':Interruptfrom~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.2/lib/spring/client/run.rb:47:in`verify_server_version'from~/.rvm/gems/ruby-2.1.1/gems/spring-1.1.

  3. ruby-on-rails - openshift 上的 rails 控制台 - 2

    我将我的Rails应用程序部署到OpenShift,它运行良好,但我无法在生产服务器上运行“Rails控制台”。它给了我这个错误。我该如何解决这个问题?我尝试更新ruby​​gems,但它也给出了权限被拒绝的错误,我也无法做到。railsc错误:Warning:You'reusingRubygems1.8.24withSpring.UpgradetoatleastRubygems2.1.0andrun`gempristine--all`forbetterstartupperformance./opt/rh/ruby193/root/usr/share/rubygems/rubygems

  4. Unity 热更新技术 | (三) Lua语言基本介绍及下载安装 - 2

    ?博客主页:https://xiaoy.blog.csdn.net?本文由呆呆敲代码的小Y原创,首发于CSDN??学习专栏推荐:Unity系统学习专栏?游戏制作专栏推荐:游戏制作?Unity实战100例专栏推荐:Unity实战100例教程?欢迎点赞?收藏⭐留言?如有错误敬请指正!?未来很长,值得我们全力奔赴更美好的生活✨------------------❤️分割线❤️-------------------------

  5. C51单片机——实现用独立按键控制LED亮灭(调用函数篇) - 2

    说在前面这部分我本来是合为一篇来写的,因为目的是一样的,都是通过独立按键来控制LED闪灭本质上是起到开关的作用,即调用函数和中断函数。但是写一篇太累了,我还是决定分为两篇写,这篇是调用函数篇。在本篇中你主要看到这些东西!!!1.调用函数的方法(主要讲语法和格式)2.独立按键如何控制LED亮灭3.程序中的一些细节(软件消抖等)1.调用函数的方法思路还是比较清晰地,就是通过按下按键来控制LED闪灭,即每按下一次,LED取反一次。重要的是,把按键与LED联系在一起。我打算用K1来作为开关,看了一下开发板原理图,K1连接的是单片机的P31口,当按下K1时,P31是与GND相连的,也就是说,当我按下去时

  6. ruby-on-rails - 在 Rails 控制台中使用 asset_path - 2

    在我的Character模型中,我添加了:字符.rbbefore_savedoself.profile_picture_url=asset_path('icon.png')end但是,对于数据库中已存在的所有角色,它们的profile_picture_url为nil。因此,我想进入控制台并遍历所有这些并进行设置。在我试过的控制台中:Character.find_eachdo|c|c.profile_picture_url=asset_path('icon.png')end但这给出了错误:NoMethodError:undefinedmethod`asset_path'formain:O

  7. ruby-on-rails - 带有 Pry 的 Rails 控制台 - 2

    当我进入Rails控制台时,我已将pry设置为加载代替irb。我找不到该页面或不记得如何将其恢复为默认行为,因为它似乎干扰了我的Rubymine调试器。有什么建议吗? 最佳答案 我刚发现问题,pry-railsgem。忘记了它的目的是让“railsconsole”打开pry。 关于ruby-on-rails-带有Pry的Rails控制台,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/question

  8. ruby - 将全局 $stdout 重新分配给控制台 - ruby - 2

    我正在尝试将$stdout设置为临时写入一个文件,然后返回到一个文件。test.rb:old_stdout=$stdout$stdout.reopen("mytestfile.out",'w+')puts"thisgoesinmytestfile"$stdout=old_stdoutputs"thisshouldbeontheconsole"$stdout.reopen("mytestfile1.out",'w+')puts"thisgoesinmytestfile1:"$stdout=old_stdoutputs"thisshouldbebackontheconsole"这是输出。r

  9. ruby-on-rails - Ruby 流量控制 : throw an exception, 返回 nil 还是让它失败? - 2

    我在思考流量控制的最佳实践。我应该走哪条路?1)不要检查任何东西并让程序失败(更清晰的代码,自然的错误消息):defself.fetch(feed_id)feed=Feed.find(feed_id)feed.fetchend2)通过返回nil静默失败(但是,“CleanCode”说,你永远不应该返回null):defself.fetch(feed_id)returnunlessfeed_idfeed=Feed.find(feed_id)returnunlessfeedfeed.fetchend3)抛出异常(因为不按id查找feed是异常的):defself.fetch(feed_id

  10. ruby-on-rails - ruby 新手,有人可以帮我从控制台破译这个错误吗? - 2

    我真的只是不确定这意味着什么或我应该做什么才能让网页在我的本地主机上运行。现在它只是显示一个错误,上面写着“我们很抱歉,但出了点问题。”当我运行railsserver并在chrome中打开localhost:3000时。这是控制台输出:StartedGET"/users/sign_in"for127.0.0.1at2013-07-0512:07:07-0400ProcessingbyDevise::SessionsController#newasHTMLCompleted500InternalServerErrorin55msNoMethodError(undefinedmethod`

随机推荐