Giter Site home page Giter Site logo

ladmini / lzviewpager Goto Github PK

View Code? Open in Web Editor NEW
170.0 7.0 26.0 3.36 MB

A powerful paging view with tab bar.

License: MIT License

Swift 89.08% Ruby 10.06% Objective-C 0.85%
pager tabs pagerview tabedpager tablayout viewpages viewpager ios swift scrollcontroller

lzviewpager's Introduction

⭐️ Features

  • Support Swift 5.
  • Super easy to implement page view controller with indicator bar.
  • Simplistic, yet highly extensive customisation.
  • Full support for custom components.
  • Built on a powerful and informative page view controller.
  • Header scrollable, if the width of buttons is larger than the width of the current view.

📋 Requirements

LZViewPager requires iOS 12+ (Tested on iOS 17), Swift 5.

📲 Installation

CocoaPods

LZViewPager is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'LZViewPager'

And run pod install.

If your pod install doesn't work properly, maybe your pod repository needs to be updated. You can try

pod repo update

and then run

pod install

Carthage

LZViewPager is also available through Carthage. Simply install carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

Carthage dependency

Since this project depends on SnapKit(A Swift Autolayout DSL for iOS & OS X). You can add LZViewPager to your Cartfile like this:

github "SnapKit/SnapKit" ~> 5.0.0
github "ladmini/LZViewPager"

Swift Package Manager

dependencies: [
    .package(url: "https://github.com/ladmini/LZViewPager", .upToNextMajor(from: "1.3.1"))
]

Manually

If you prefer not to use either of the aforementioned dependency managers, you can integrate LZViewPager into your project manually. Just copy the following 3 files into your project.

  1. LZViewPager.swift
  2. LZViewPagerHeader.swift
  3. LZViewPagerContent.swift

🚀 Usage

The Basics

  1. Create a ViewController and provide a LZViewPagerDelegate, LZViewPagerDataSource

  2. Drag a UIView into ViewVontroller's view and set it's type to LZViewPager, then set an outlet variable as "viewPager"

  1. Set the items you want to display

  2. Set the hostController to self

  3. viewPager.reload()

class ViewController: BaseViewController, LZViewPagerDelegate, LZViewPagerDataSource {
    @IBOutlet weak var viewPager: LZViewPager!
    private var subControllers:[UIViewController] = []
    override func viewDidLoad() {
        super.viewDidLoad()
        viewPager.dataSource = self
        viewPager.delegate = self
        viewPager.hostController = self
        let vc1 = UIViewController.createFromNib(storyBoardId: "ContentViewController1")!
        vc1.title = "Title1"
        let vc2 = UIViewController.createFromNib(storyBoardId: "ContentViewController2")!
        vc2.title = "Title2"
        let vc3 = UIViewController.createFromNib(storyBoardId: "ContentViewController3")!
        vc3.title = "Title3"
        let vc4 = UIViewController.createFromNib(storyBoardId: "ContentViewController4")!
        vc4.title = "Title4"
        subControllers = [vc1, vc2, vc3, vc4]
        viewPager.reload()
    }
}
  1. Implement LZViewPagerDataSource.
    func numberOfItems() -> Int {
        return self.subControllers.count
    }
    
    func controller(at index: Int) -> UIViewController {
        return subControllers[index]
    }
    
    func button(at index: Int) -> UIButton {
        //Customize your button styles here
        let button = UIButton()
        button.setTitleColor(UIColor.black, for: .normal)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
        return button
    }
  1. All done! 🎉

Customization

You can customize you button styles in datasource method

func button(at index: Int) -> UIButton

you can also customize other styles by implementing other datasource methods example:

func heightForHeader() -> CGFloat // default is 40
func backgroundColorForHeader() -> UIColor // default is .white
func heightForIndicator() -> CGFloat // default is 2.0
func colorForIndicator(at index: Int) -> UIColor // default is UIColor(red: 255.0/255.0, green: 36.0/255.0, blue: 79.0/255.0, alpha: 1.0)
func shouldShowIndicator() -> Bool // default is true
func widthForButton(at index: Int) -> CGFloat // default is bounds.width / count
func widthForIndicator(at index: Int) -> CGFloat // default is equals to button's width
func buttonsAligment() -> ButtonsAlignment // default is .left
func shouldEnableSwipeable() -> Bool // default is true
func leftMarginForHeader() -> CGFloat //default is 0
func rightMarginForHeader() -> CGFloat //default is 0
func shouldShowSeparator() -> Bool // default is false
func colorForSeparator()-> UIColor // default is .white
func heightForSeparator() -> CGFloat // default is 2.0
func leftMarginForSeparator() -> CGFloat //default is 0
func rightMarginForSeparator() -> CGFloat //default is 0
func topMarginForSeparator() -> CGFloat //default is 0
func cornerRadiusForIndicator() -> CGFloat //default is 0

Delegate

Implementing delegate methods if needed

//required
func numberOfItems() -> Int
func controller(at index: Int) -> UIViewController
func button(at index: Int) -> UIButton

//optional
func didSelectButton(at index: Int)
func willTransition(to index: Int)
func didTransition(to index: Int)

Instance methods for LZViewPager

When your datasource changed you should call reload() method to refresh. If you want to locating to some page programming you can call select(index: Int, animated: Bool) method, It is important to note that animated is an optional parameter in order to be compatible with the previous versions. If you do not specify animated, it is true by default.

func reload()
public func select(index: Int, animated: Bool = true)

Instance property for LZViewPager

public var currentIndex: Int?

How to run this demo

  1. Clone this repository
  2. Execute carthage update
  3. Build and Run

⚠️ Troubleshooting

If you are encountering issues with LZViewPager, please raise an issue.

👨🏻‍💻 About

❤️ Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/ladmini/LZViewPager.

👮🏻‍♂️ License

The library is available as open source under the terms of the MIT License.

lzviewpager's People

Contributors

haitec avatar ladmini avatar tobaloidee 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  avatar  avatar  avatar  avatar

lzviewpager's Issues

Proposal: Remove snapkit dependency

What do you think about removing the snapkit dependency and create constraint with the standard UIKit syntax? Will you accept a pull request of this kind?

重新載入的時候,會發生Crash

我的數據源(10筆),有異動(變9筆)需要reloadData, 而畫面已經滑動到最後一個, 這時reloadData,會死在
func buttonXLeading(for index: Int) ,因為沒有歸0 , index回傳給我10
需要哥 做個防呆,在 func setUpIndicator() 發現 self.currentIndex > self.dataSource.numberOfItems 要歸零

Header isn't scrolling

Screen Shot 2020-07-15 at 13 35 09

Following demo, but for some reason header isn't scrolling. On version 1.2.5 Xcode 11.5 if you need any code please let me know

Pagination Issue.

When i Press Button Fastly of Segments then the Loading of Page Create Issue. Some Time second tab shows ViewController of Third tab ViewController and These Navigation Issue came normaly.

Logo Proposal

Good day @ladmini I am a graphic designer and i would like to contribute to your good project by designing a logo for it. I'll be doing it for free if you will allow me Sir..Thanks and best regards!
-Tobaloidee

Title color instead of indicator

Hi!

I would like title color black when active and gray when inactive the page (instead of use indicator).

button.setTitleColor(UIColor.black, for: .selected) button.setTitleColor(UIColor.black.withAlphaComponent(0.2), for: .normal)

This code is working, but my first/ main page title will black/active only when I tap. How can I make the first title "button" active default (100% black)?

Thanks

button text not changing

changing text on viewdidload by doing vc1.title = "home" and vc2.title = "align" but text not changing

how to change Indicator Not Selected Area Color

By Default, it shows White Color for Indicator Which is Not Selected.
Screenshot 2020-12-17 at 4 25 17 PM
I want to Change the Color Of the UnSelected area or I want to make its color Clear.
How to do it. I am not Getting any solution for that.
Please help me as soon as possible.

Cannot load underlying module for 'LZViewPager'

Hello guys, I'm facing this issue only with a custom build configuration, we have:

Debug: Everything is OK
PRE: KO, we get Cannot load underlying module for 'LZViewPager'
Release: Everything is OK
Any help? Thanks for your job!

Can't change for indicator height

Hi,
I was using the function below but it didn't work.

  • func heightForIndicator(at index: Int)

Please let me know if I miss anything.
Thanks,

能否给指示线加一个切换的动画

这个框架很类似Android的ViewPager用法,很亲切

但是指示线 在切换的时候有些生硬,作者能否加上一些随着手滑动,线跟着滑动的动画

why causing this error?

Thread 1: "[<UIView 0x7fc42d60d0d0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource."

please help

如何在父页面,选择要展示的子页面,哪个排第一个

这是个好框架,很简洁,最近遇到一个问题,我的父页面有4个按钮,子页面同样也有4个,我想点击对应的按钮进入后自动将该页面显示出来,我在子页面 viewDidLoad 里面添加了viewPager.select(index: pageViewIndex) pageViewIndex是定义的全局变量,在父页面跳转的时候改变变量来记录选中了哪个.
这样也可以工作,但是子页面间切换的时候title要闪烁,左右滑动也不是按顺序滑动,所以问下这个该怎么解决呢

App Crash when comes to LZVewPage Screen

I am using this library in my project and whenever I run my app it is giving me the following error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIView 0x7fccc110d3e0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key dataSource.'

Doesn't show content viewcontroller inside of viewPager

import LZViewPager

class rechargeViewController: BaseViewController, LZViewPagerDelegate, LZViewPagerDataSource{

@IBOutlet weak var viewPager: LZViewPager!


  private var subControllers:[UIViewController] = []
    
override func viewDidLoad() {
        
           super.viewDidLoad()

           let vc1 = UIViewController.createFromNib(storyBoardId: "prePayTypesViewController")!
           vc1.title = "PREPAID"
           let vc2 = UIViewController.createFromNib(storyBoardId: "dthViewController")!
           vc2.title = "DTH"
           let vc3 = UIViewController.createFromNib(storyBoardId: "landLineViewController")!
           vc3.title = "LANDLINE"
           let vc4 = UIViewController.createFromNib(storyBoardId: "broadBandViewController")!
           vc4.title = "BROADBAND"
           let vc5 = UIViewController.createFromNib(storyBoardId: "postPayViewController")!
           vc4.title = "POSTPAY"
           let vc6 = UIViewController.createFromNib(storyBoardId: "autoViewController")!
           vc4.title = "AUTO"
           subControllers = [vc1, vc2, vc3, vc4, vc5, vc6]
           viewPager.hostController = self
           viewPager.reload()

       }

    func numberOfItems() -> Int {
       return self.subControllers.count
   }
   
   func controller(at index: Int) -> UIViewController {
       return subControllers[index]
   }
   
   func button(at index: Int) -> UIButton {
       //Customize your button styles here
       let button = UIButton()
       button.setTitleColor(UIColor.black, for: .normal)
       button.titleLabel?.font = UIFont.systemFont(ofSize: 16)
       return button
   }

           func widthForButton(at index: Int) -> CGFloat {
               return 130
           }

           func willTransition(to index: Int) {
               print("Current index before transition: \(viewPager.currentIndex ?? -1)")
           }

           func didTransition(to index: Int) {
               print("Current index after transition: \(viewPager.currentIndex ?? -1)")
           }

           func didSelectButton(at index: Int) {
               print("Current index before transition: \(viewPager.currentIndex ?? -1)")
               print("Current index after transition: \(index)")
           }

}

LZViewPager Not Obliging by Auto Layout Constraints

Hi,

I'm a recent installer of your library and I ran across an issue where the LZViewPager will not let me create a custom approach, such as modifying the NSLayoutConstraints. I have been trying to create my own layout constraints with the LZViewPager (since my view controller is dynamic) and it won't let me no matter what I do. Here is a snippet of what I am trying to achieve.

let viewHeader = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth, height: 200))
var viewPager = LZViewPager(frame: CGRect(x: 0, y: 0, width: screenWidth, height: 100))
viewPager.translatesAutoresizingMaskIntoConstraints = false

self.view.addSubview(viewPager)
self.view.addSubview(viewHeader)

NSLayoutConstraint.activate([
self.viewHeader.topAnchor.constraint(equalTo: self.view.topAnchor, constant: 0),
self.viewHeader.leadingAnchor.constraint(equalTo: self.view.leadingAnchor, constant: 0),
self.viewHeader.trailingAnchor.constraint(equalTo: self.view.trailingAnchor, constant: 0),
self.viewHeader.heightAnchor.constraint(equalToConstant: 200),

   self.viewPager.topAnchor.constraint(equalTo: self.viewHeader.bottomAnchor, constant: 0),
   self.viewPager.leadingAnchor.constraint(equalTo: self.viewHeader.leadingAnchor, constant: 0),
   self.viewPager.trailingAnchor.constraint(equalTo: self.viewHeader.trailingAnchor, constant: 0),
   self.viewPager.bottomAnchor.constraint(equalTo: self.viewHeader.bottomAnchor, constant: 0),

])

For some reason the above will not allow me to change the LZViewPager's constraints. No matter correctly done the auto layout is. Can you please apply an update to fix this or assist me with this issue? Thanks

LZViewPager doesn't support localization

I've used this library for pageviewcontroller and now im facing issue as i also have localization in my app so when i switch to arabic that is from right to left. The LZViewPager just disappears from navigation bar place. For reference i already used the below code in the same viewcontroller file. But it isnt working. Reply expected as soon as possible. As i have used this in a important project

func buttonsAlignment() -> ButtonsAlignment {
if let lang = Locale.current.languageCode, lang == "ar" || lang == "ur" {
return .center // i have changed and values and tested
} else {
return .center
}
}

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.