Code Monkey home page Code Monkey logo

llsegmentviewcontroller's Introduction

LLSegmentViewController

要求

  • iOS 8.0+
  • Xcode 9
  • Swift

使用CocoaPods安装

pod 'LLSegmentViewController'

特征

1、预加载控制器View

pageView.preLoadRange = 1...3 //当前控制器的左边预加载1个,右边预加载3个

2、红点设置简单,跟当前控制器绑定,不再需要写额外控制代码

self.tabBarItem.badgeValue = "\(indexPath.row)"//红点设置为LLSegmentRedBadgeValue

3、自定义性强:参考自定义样式

项目中的使用

class SimpDemoViewController: LLSegmentViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
        loadSegmentedConfig()
    }
}

extension SimpDemoViewController{
    func loadSegmentedConfig() {
        layoutContentView()
        loadCtls()
        setUpSegmentStyle()
    }

    func layoutContentView() {
        self.layoutInfo.segmentControlPositionType = .top(size: CGSize.init(width: UIScreen.main.bounds.width, height: 44),offset:0)
        self.relayoutSubViews()
    }

    func loadCtls() {
        let introCtl = UIViewController()
        introCtl.title = "简介"
        introCtl.view.backgroundColor = UIColor.yellow
        
        let catalogCtl = UIViewController()
        catalogCtl.title = "目录"
        catalogCtl.view.backgroundColor = UIColor.red
        
        let ctls =  [introCtl,catalogCtl]
        reloadViewControllers(ctls:ctls)
    }

    func setUpSegmentStyle() {
        let itemStyle = LLSegmentItemTitleViewStyle()
        itemStyle.selectedColor = UIColor.init(red: 50/255.0, green: 50/255.0, blue: 50/255.0, alpha: 1)
        itemStyle.unSelectedColor = UIColor.init(red: 136/255.0, green: 136/255.0, blue: 136/255.0, alpha: 1)
        itemStyle.selectedTitleScale = 1
        itemStyle.titleFontSize = 15
        itemStyle.itemWidth = UIScreen.main.bounds.width/CGFloat(ctls.count)//如果不指定是自动适配的
        //这里可以继续增加itemStyle的其他配置项... ...

        segmentCtlView.backgroundColor = UIColor.white
        segmentCtlView.separatorLineShowEnabled = true //间隔线显示,默认不显示
        //还有其他配置项:颜色、宽度、上下的间隔...

        segmentCtlView.bottomSeparatorStyle = (1,UIColor.red) //分割线:默认透明色
        segmentCtlView.indicatorView.widthChangeStyle = .stationary(baseWidth: 11)//横杆宽度:有默认值
        segmentCtlView.indicatorView.centerYGradientStyle = .bottom(margin: 0)//横杆位置:有默认值
        segmentCtlView.indicatorView.shapeStyle = .custom //形状样式:有默认值

        var segmentedCtlStyle = LLSegmentedControlStyle()
        segmentedCtlStyle.segmentItemViewClass = LLSegmentItemTitleView.self  //ItemView和ItemViewStyle要统一对应
        segmentedCtlStyle.itemViewStyle = itemStyle
        segmentCtlView.reloadData(ctlViewStyle: segmentedCtlStyle)
    }

自定义

只需两步就可完成自定义效果:(可参考项目内的自定义样式)

  • 1、继承LLSegmentBaseItemView或子类;
  • 2、实现LLSegmentBaseItemView以下方法(有些方法可实现可不实现)
//1、设置标题
public func titleChange(title:String)
//2、滚动时会调用这个方法,percent的取值范围是0...1
public func percentChange(percent:CGFloat)
//3、返回当前ItemView的宽度
public func itemWidth() ->CGFloat
//4、设置Item的style样式
public func setSegmentItemViewStyle(itemViewStyle:LLSegmentItemViewStyle) 

效果预览

详情页效果预览

说明 Gif
个人中心头部放大
个人中心列表刷新
商品详情

指示器效果预览

说明 Gif
LineView固定宽度
LineView京东风格
LineView爱奇艺风格
LineView回旋风格
LineView与Item等宽
LineView分割线
LineView背景
LineView椭圆形
LineView椭圆形加阴影
LineView文字遮罩
LineView文字遮罩加背景
LineView文字遮罩加背景和阴影
LineView三角形
LineView小红点加数字
LineView点线效果
LineViewQQ红点

特殊效果预览

说明 Gif
LineView嵌套
LineView足球
LineView插入
LineView混合
LineView图片做背景
LineView图片文字

自定义Item效果预览

说明 Gif
LineView背景色渐变
LineView富文本
LineView网易新闻

自定义tabbar效果预览

说明 Gif
LineView微信
LineView微博
LineView图片做背景

邮箱:[email protected]
QQ群: 142649183

llsegmentviewcontroller's People

Contributors

coderlinlee avatar pws123 avatar xusion avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

llsegmentviewcontroller's Issues

如何感知到滑动到顶部和底部呢。

在demo里的->详情页->列表刷新中。我需要接收headview滑动到顶部和正常展开的headview两种状态。我似乎没有在里面看到有对应的事件。希望可以指点下。谢谢。

pageView子vc里的tableview数据高度不够时 滚动问题

pageView子vc里的tableview数据高度不够时,上拉整体滚动到底部后,再往上拉,不松开手势,整体视图滚动回到顶部后,tableview的下拉刷新控件拉不出来,一直有弹性效果。需要松开手,再次下拉,下拉刷新控件才能正常显示

带headView

有系统的nav的时候,带headView无法滑动到顶部
class DVideoController:LLSegmentViewController{
}
DVideoController是tabbar上的第三个页面,带系统的导航栏的
func layoutContentView() {

    hotPagerView.frame =  CGRect(x: 0, y:0, width: kScreenW, height: 104)
   self.layoutInfo.headView = hotPagerView
    
    self.layoutInfo.refreshType = .container
    self.layoutInfo.segmentControlPositionType = .top(size: CGSize.init(width: UIScreen.main.bounds.width, height: 40),offset:0)
    self.relayoutSubViews()
}

请问是什么原因导致headview无法滑动到最底部一直有一个导航栏的高度无法滑动

Crash on iOS 10.3.3 Device

2019-03-21 00:36:14.710 LLSegmentViewController[27670:907558] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'An instance 0x600000148f00 of class UITabBarItem was deallocated while key value observers were still registered with it. Current observation info: <NSKeyValueObservationInfo 0x608000426140> (
<NSKeyValueObservance 0x600000244d70: Observer: 0x7fc7ea60b0d0, Key path: badgeValue, Options: <New: YES, Old: NO, Prior: NO> Context: 0x0, Property: 0x600000242f40>
)'
*** First throw call stack:
(
0 CoreFoundation 0x0000000108070b0b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x0000000104e20141 objc_exception_throw + 48
2 CoreFoundation 0x00000001080d9625 +[NSException raise:format:] + 197
3 Foundation 0x000000010495bb53 NSKVODeallocate + 294
4 libobjc.A.dylib 0x0000000104e34b8e _ZN11objc_object17sidetable_releaseEb + 202
5 UIKit 0x0000000105e00b13 -[UIViewController .cxx_destruct] + 913
6 libobjc.A.dylib 0x0000000104e1e9bc _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
7 libobjc.A.dylib 0x0000000104e2ad34 objc_destructInstance + 129
8 libobjc.A.dylib 0x0000000104e2ad66 object_dispose + 22
9 UIKit 0x0000000105e4ea21 -[UIResponder dealloc] + 145
10 UIKit 0x0000000105dd8cca -[UIViewController dealloc] + 1846
11 libswiftCore.dylib 0x000000010779acfb swift_arrayDestroy + 59
12 libswiftCore.dylib 0x00000001075351e6 $Ss23_ContiguousArrayStorageCfD + 54
13 libswiftCore.dylib 0x00000001077a6910 _swift_release_dealloc + 16
14 LLSegmentViewController 0x000000010463f2e0 $SSaySo16UIViewControllerCGWOh + 16
15 libobjc.A.dylib 0x0000000104e1e9bc _ZL27object_cxxDestructFromClassP11objc_objectP10objc_class + 127
16 libobjc.A.dylib 0x0000000104e2ad34 objc_destructInstance + 129
17 libobjc.A.dylib 0x0000000104e2ad66 object_dispose + 22
18 UIKit 0x0000000105e4ea21 -[UIResponder dealloc] + 145
19 UIKit 0x0000000105cce318 -[UIView dealloc] + 1874
20 LLSegmentViewController 0x000000010467903b $S23LLSegmentViewController18LLSegmentedControlCfD + 363
21 LLSegmentViewController 0x0000000104679094 $S23LLSegmentViewController18LLSegmentedControlCfDTo + 36
22 libobjc.A.dylib 0x0000000104e352fa _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 866
23 UIKit 0x0000000105cce2f7 -[UIView dealloc] + 1841
24 UIKit 0x0000000105d08ef0 -[UIScrollView dealloc] + 833
25 LLSegmentViewController 0x000000010462cf36 $S23LLSegmentViewController017LLContainerScrollB0CfD + 198
26 LLSegmentViewController 0x000000010462d2d4 $S23LLSegmentViewController017LLContainerScrollB0CfDTo + 36
27 Foundation 0x000000010495ba8d NSKVODeallocate + 96
28 libobjc.A.dylib 0x0000000104e352fa _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 866
29 UIKit 0x0000000105cce2f7 -[UIView dealloc] + 1841
30 libobjc.A.dylib 0x0000000104e352fa _ZN12_GLOBAL__N_119AutoreleasePoolPage3popEPv + 866
31 CoreFoundation 0x0000000107fbfe96 _CFAutoreleasePoolPop + 22
32 CoreFoundation 0x0000000107ffbaec __CFRunLoopRun + 2172
33 CoreFoundation 0x0000000107ffb016 CFRunLoopRunSpecific + 406
34 GraphicsServices 0x000000010ae57a24 GSEventRunModal + 62
35 UIKit 0x0000000105c39134 UIApplicationMain + 159
36 LLSegmentViewController 0x000000010465af14 main + 68
37 libdyld.dylib 0x000000010964e65d start + 1
38 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException

滑动触发点击事件

引入到自己项目中, ContainerScollerView容器中, 具有点击事件的子视图, 数量为单个时, 上下滑动子视图会触发其点击事件, 不知道为什么, demo中却没问题, 希望作者有时间看下, 😂

无法选中指定tab

open func selected(at Index:NSInteger,animation:Bool)  {
    guard (ctls.count < Index && Index > 0) else {
        return
    }
    segmentCtlView.selected(at: Index, animation: animation)
}

guard (ctls.count < Index && Index > 0) else { return } 这个判断不对吧

xr/xs适配

在xr/xs上 顶部segmentCtlView会一起滚动

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.