Giter Club home page Giter Club logo

jnsegmentedcontrol's Introduction

JNSegmentedControl

CI Status Version License Platform

JNSegmentedControl is an easy to use, animated segmented control for iOS written in Swift.
JNSegmentedControl supports 3 main styles of segments: text only, image only, text with image on (under, above, before and after text).

Preview

Requirements:

  • Xcode 9
  • iOS 9.0+
  • Swift 4.2+

Installation

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

pod 'JNSegmentedControl'

Usage:

  • Import JNSegmentedControl module
import JNSegmentedControl
  • Initalization:

    • Storyboard: Manually, you can add a UIView instance to your Xib, set 'JNSegmentedControl' class and connect @IBOutlet reference.

    • Programmatically: Init ‘JNSegmentedControl’ UIView instance programatically.

        let segmentedControlView = JNSegmentedCollectionView()
        self.view.addSubview(segmentedControlView)
  • Setup:

    • JNSegmentedControl Setup:
        self.segmentedControlView.setup(
            items: [NSAttributedString],
            selectedItems: [NSAttributedString],
            options: JNSegmentedCollectionOptions(),
            badgeCounts: [Int]
        )

    To start with default options you can pass (nil) value to the options parameter.

        self.segmentedControlView.setup(
            items: [NSAttributedString],
            selectedItems: [NSAttributedString],
            options: nil,
            badgeCounts: []
        )
    • Configuring items:

    The Segmented Control items & selected items are array of NSAttributedString. In order to set items you need to provide an instance of [NSAttributedString].

    • Default Items:

          var items = [NSAttributedString]()
          let item  = NSAttributedString(string: “Default Item", attributes: [])
          items.append(item)
      
    • Selected Items:

          var items = [NSAttributedString]()
          let item  = NSAttributedString(string: “Selected Item", attributes: [])
          items.append(item)
      
  • Handling callback:

        self.segmentedControlView.didSelectItem = { segment in
            print("Selected item: ", segment)
        }
  • Options Customization:

    • backgroundColor: Segmented control background color.
    • itemOptionType: case value from JNSegmentedCollectionItemOptionType enumeration.
    • layoutType: case value from JNSegmentedCollectionLayoutType enumeration.
    • verticalSeparatorOptions: instance from JNSegmentedCollectionItemVerticalSeparatorOptions struct as vertical separator between segments.
    • scrollEnabled: segmented control is scrolling enabled.
    • contentItemLayoutMargins: Content item layout margins from Left and Right.
        JNSegmentedCollectionOptions(
            backgroundColor: UIColor.white,
            itemOptionType: JNSegmentedCollectionItemOptionType, 
            layoutType: JNSegmentedCollectionLayoutType.dynamic, 
            verticalSeparatorOptions: JNSegmentedCollectionItemVerticalSeparatorOptions? = nil,
            scrollEnabled: true,
            contentItemLayoutMargins: 10.0
        )
  • JNSegmented Collection Item Option Type:

    The Segmented Control Item has two types of layout for items:

    • single(option: JNSegmentedCollectionItemOptions): Single option for all items.
    • multiple(options: [JNSegmentedCollectionItemOptions]): Multiple option for all items.
        enum  JNSegmentedCollectionItemOptionType {
            case single(option: JNSegmentedCollectionItemOptions) 
            case multiple(options: [JNSegmentedCollectionItemOptions]) 
        }
  • JNSegmented Collection Item Options:

    The Segmented Control has the ability to configure each item, that has the following settings:

    • CornerRadius: Corner radius for container view.
    • BackgroundColor: Background color for container view.
    • SelectedBackgroundColor: Selected background color for container view.
    • BadgeBackgroundColor: Badge background color for badge count.
    • SelectedBadgeBackgroundColor: Selected badge background color for badge count.
    • BadgeFont: Badge count font.
    • SelectedBadgeFont: Selected badge count font.
    • BadgeTextColor: Badge count text color.
    • SelectedBadgeTextColor: Selected badge count text color.
        JNSegmentedCollectionItemOptions(cornerRadius: 10.0, 
                backgroundColor: #colorLiteral(red: 0.456212461, green: 0.7545028329, blue: 0.8568375707, alpha: 1),
                selectedBackgroundColor: #colorLiteral(red: 0.1984777451, green: 0.7956866622, blue: 1, alpha: 1),
                badgeBackgroundColor: .white, 
                selectedBadgeBackgroundColor: .white,
                badgeFont: UIFont.systemFont(ofSize: 16.0), 
                selectedBadgeFont: UIFont.systemFont(ofSize: 16.0), 
                badgeTextColor: .gray, selectedBadgeTextColor: .gray)
  • JNSegmented Collection Layout Type:

    The Segmented Control has two types of layout for items:

    • Dynamic: The width of each item will be according to its content.
    • Fixed: The width of each item will be fixed according to max visible Items.
        enum  JNSegmentedCollectionLayoutType {
            case dynamic
            case fixed(maxVisibleItems: Int)
        }
  • JNSegmented Vertical Separator Options:

    The Segmented Control has the ability to show separator line between items, that has the following settings:

    • HeigthRatio: Separator view height Ratio accroding to collection view height, max value is 1 and min is 0.
    • Width: Separator view width.
    • Color: Separator view background color.
        JNSegmentedCollectionItemVerticalSeparatorOptions (
            heigthRatio: 0.3, 
            width: 1.0,
            color: UIColor.blue
        )

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Author

Jayel Zaghmoutt, Mohammad Nabulsi & Mohammad Ihmouda

License

JNSegmentedControl is available under the MIT license. See the LICENSE file for more info.

jnsegmentedcontrol's People

Contributors

ihmouda avatar jayelzaghmoutt avatar masa-qzaih avatar mohammadnabulsi avatar yara-abuhijleh1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

jnsegmentedcontrol's Issues

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.