All Projects → sasojadrovski → Sjfluidsegmentedcontrol

sasojadrovski / Sjfluidsegmentedcontrol

Licence: mit
A segmented control with custom appearance and interactive animations. Written in Swift 3.0.

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Sjfluidsegmentedcontrol

react-native-segment-control
Swipeable SegmentedControl component for React Native apps
Stars: ✭ 21 (-97.56%)
Mutual labels:  segment, control, animated
Homebridge Garagedoor Command
Homebridge plugin to control a garage door using command line functions
Stars: ✭ 18 (-97.91%)
Mutual labels:  control
Driveway
pure CSS masonry layouts
Stars: ✭ 607 (-29.58%)
Mutual labels:  segment
Radar
实时风控引擎(Risk Engine),自定义规则引擎(Rule Script),完美支持中文,适用于反欺诈(Anti-fraud)应用场景,开箱即用!!!移动互联网时代的风险管理利器,你 Get 到了吗?
Stars: ✭ 781 (-9.4%)
Mutual labels:  control
Jquery.localscroll
Animated anchor navigation made easy with jQuery
Stars: ✭ 624 (-27.61%)
Mutual labels:  animated
Jeelizweboji
JavaScript/WebGL real-time face tracking and expression detection library. Build your own emoticons animated in real time in the browser! SVG and THREE.js integration demos are provided.
Stars: ✭ 835 (-3.13%)
Mutual labels:  animated
Hvscrollview
这不是框架,只是3个示例程序,给大家提供一个实现这种布局的思路
Stars: ✭ 584 (-32.25%)
Mutual labels:  segment
Randomix
🎲 An open source app to choose randomly between numbers, answers, options and so on.
Stars: ✭ 24 (-97.22%)
Mutual labels:  animated
React Native Animated Tabbar
A 60FPS animated tab bar with a variety of cool animation presets 😎
Stars: ✭ 890 (+3.25%)
Mutual labels:  animated
Fancontrol.releases
This is the release repository for Fan Control, a highly customizable fan controlling software for Windows.
Stars: ✭ 768 (-10.9%)
Mutual labels:  control
Uncap
Map Caps Lock to Escape or any key to any key
Stars: ✭ 705 (-18.21%)
Mutual labels:  control
Deepdrive
Deepdrive is a simulator that allows anyone with a PC to push the state-of-the-art in self-driving
Stars: ✭ 628 (-27.15%)
Mutual labels:  control
Numericaltextentry
An iOS library for beautiful number entry fields. iPad friendly. Written in Swift.
Stars: ✭ 16 (-98.14%)
Mutual labels:  animated
Pytorch scatter
PyTorch Extension Library of Optimized Scatter Operations
Stars: ✭ 618 (-28.31%)
Mutual labels:  segment
Aiflatswitch
Nicely animated flat design switch alternative to UISwitch
Stars: ✭ 904 (+4.87%)
Mutual labels:  animated
Jxcategoryview
A powerful and easy to use category view (segmentedcontrol, segmentview, pagingview, pagerview, pagecontrol) (腾讯新闻、今日头条、QQ音乐、网易云音乐、京东、爱奇艺、腾讯视频、淘宝、天猫、简书、微博等所有主流APP分类切换滚动视图)
Stars: ✭ 5,561 (+545.13%)
Mutual labels:  segment
Osqp
The Operator Splitting QP Solver
Stars: ✭ 689 (-20.07%)
Mutual labels:  control
Dypiechartview
Animated Pie Chart using Custom CALayer.
Stars: ✭ 5 (-99.42%)
Mutual labels:  animated
React Native Scrollable Tab View
Tabbed navigation that you can swipe between, each tab can have its own ScrollView and maintain its own scroll position between swipes. Pleasantly animated. Customizable tab bar
Stars: ✭ 6,784 (+687.01%)
Mutual labels:  animated
Christmas Tree
ASCII christmas-tree with animations for 256 colored terminals
Stars: ✭ 23 (-97.33%)
Mutual labels:  animated

SJFluidSegmentedControl

Version Downloads License Platform Language

About

If you are bored with using the default UISegmentedControl, this might save your day. SJFluidSegmentedControl is a customizable segmented control with an interactive transition, written in Swift 3.0 and it is based on LUNSegmentedControl by LunApps which is written in Objective-C.

Sample

Example

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

Requirements

  • iOS 8.0+
  • Xcode 8.0+
  • Swift 3.0+

Note: SJFluidSegmentedControl is not intended to be used from Objective-C. For an Objective-C version of this library, please refer to the LUNSegmentedControl.

Features

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Apps using this library

If your app is using this library, I would love to add it to this README. Please reach out to me!

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. You can install it with the following command:

$ gem install cocoapods

CocoaPods 1.1.0+ is required to build SJFluidSegmentedControl 1.0.0+.

To integrate SJFluidSegmentedControl into your Xcode project using CocoaPods, specify it in your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

target '<Your Target Name>' do
    pod 'SJFluidSegmentedControl', '~> 1.0'
end

Then, run the following command:

$ pod install

Manual installation

SJFluidSegmentedControl can also be installed manually by simply dragging and dropping the files located in the Classes folder.

Usage

Using Interface Builder

  1. Drag & drop a UIView in the View.
    • By setting the background color of this view, you will also be setting the background color of the segmented control.
  2. Change its class to SJFluidSegmentedControl.
  3. Connect its data source.
  4. Implement the only required data source method that returns the number of segments in the segmented control:
func numberOfSegmentsInSegmentedControl(_ segmentedControl: SJFluidSegmentedControl) -> Int

Additionaly, you can set the cornerRadius, textColor, selectedSegmentTextColor, selectorViewColor, applyCornerRadiusToSelectorView, gradientBounceColor, shadowShowDuration, shadowHideDuration and shadowsEnabled properties by using the Attributes inspector.

Attributes

For customizing other of the available properties, create an @IBOutlet of the segmented control and access them via code.

Using Code

It's very similar to using Interface Builder, instead you just setup the custom view in code. There are several methods to do this, here's an example:

// Conform to the data source (optionally, you can conform to the delegate)
class ViewController: UIViewController, SJFluidSegmentedControlDataSource {

	// Define a lazy var
	lazy var segmentedControl: SJFluidSegmentedControl = {
	    [unowned self] in
	    // Setup the frame per your needs
	    let segmentedControl = SJFluidSegmentedControl(frame: CGRect(x: 0, y: 0, width: 300, height: 50))
	    segmentedControl.dataSource = self
	    return segmentedControl
	}()

	// Add it as a subview in viewDidLoad()
	override func viewDidLoad() {
		super.viewDidLoad()
		view.addSubview(segmentedControl)
	}

	// Don't forget to implement the required data source method
	func numberOfSegmentsInSegmentedControl(_ segmentedControl: SJFluidSegmentedControl) -> Int {
		return 3
	}

}

Data Source Implementation

You must implement the required data source method that returns the number of segments:

func numberOfSegmentsInSegmentedControl(_ segmentedControl: SJFluidSegmentedControl) -> Int

Return the titles for the segments of the segmented control, and take advantage of the NSAttributedString features to customize the text appearance using the following data source methods:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     titleForSegmentAtIndex index: Int) -> String?
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     attributedTitleForSegmentAtIndex index: Int) -> NSAttributedString?

If necessary, you can set the titles for the selected state of the segments with the help of the following data source methods:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     titleForSelectedSegmentAtIndex index: Int) -> String?
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     attributedTitleForSelectedSegmentAtIndex index: Int) -> NSAttributedString?

You can also set the title color for the selected state of the segments using this data source method:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     titleColorForSelectedSegmentAtIndex index: Int) -> UIColor

In addition, you can set a color (or an array of colors to form a gradient) for each segment, as well as colors for the left and right bounces with the help of the following data source methods:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     gradientColorsForSelectedSegmentAtIndex index: Int) -> [UIColor]
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     gradientColorsForBounce bounce: SJFluidSegmentedControlBounce) -> [UIColor]

If you need a more complex layout for each segment, you can return a custom view instead with these data source methods:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     viewForSegmentAtIndex index: Int) -> UIView
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     viewForSelectedSegmentAtIndex index: Int) -> UIView

Delegate Implementation

The delegate methods provide callbacks for some of the most commonly needed events, such as:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     didChangeFromSegmentAtIndex fromIndex: Int,
                                     toSegmentAtIndex toIndex:Int)
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     willChangeFromSegment fromSegment: Int)
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     didScrollWithXOffset offset: CGFloat)

Additionaly, if you need to take control over the transitions between the segments, you can use the following delegate methods:

@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     setupSegmentAtIndex segmentIndex: Int,
                                     unselectedView unselectedSegmentView: UIView,
                                     selectedView selectedSegmentView: UIView,
                                     withSelectionPercent percent: CGFloat)
@objc optional func segmentedControl(_ segmentedControl: SJFluidSegmentedControl,
                                     resetSegmentAtIndex segmentIndex: Int,
                                     unselectedView unselectedSegmentView: UIView,
                                     selectedView selectedSegmentView: UIView)

Additional properties

Other customization options are available through the following publicly available properties:

// The index of the currently selected segment. It ranges from 0 to segmentsCount-1. Default is `0`.
open var currentSegment: Int

// The number of segments in the segmented control. Default is `1`.
fileprivate(set) public var segmentsCount: Int

// The transition style between the default and selected state of the segments. Default is `.fade`.
open var transitionStyle: SJFluidSegmentedControlTransitionStyle

// The style of the selecton shape. Default is `.liquid`.
open var shapeStyle: SJFluidSegmentedControlShapeStyle

// The corner radius of the segmented control. Default is `0.0`.
@IBInspectable open var cornerRadius: CGFloat

// The color of the text for the default state of a segment. Default is `.black`. This property will be overriden if the delegate for attributed titles/views is implemented.
@IBInspectable open var textColor: UIColor

// The color of the text for the selected state of a segment. Default is `.white`. This property will be overriden if the delegate for attributed titles for selected state or views for selected state is implemented.
@IBInspectable open var selectedSegmentTextColor: UIColor

// The text font for the titles of the segmented control in both states if the data source does not provide attributed titles or views. Default is `.systemFont(ofSize: 14)`.
open var textFont: UIFont

// The color of the selector. Default is `.clear`. **Note:** If set, it is overlayed over the gradient colors.
@IBInspectable open var selectorViewColor: UIColor

// A boolean value to determine whether the selector should have rounded corners. Default is `false`.
@IBInspectable open var applyCornerRadiusToSelectorView: Bool

// The color for the bounce if the data source does not provide colors for bounces. Default is `.red`.
@IBInspectable open var gradientBounceColor: UIColor

// The duration of the show shadow animation. Default is `0.5`.
@IBInspectable open var shadowShowDuration: CGFloat

// The duration of the hide shadow animation. Default is `0.8`.
@IBInspectable open var shadowHideDuration: CGFloat

// A boolean value to determine whether shadows should be applied. Default is `true`.
@IBInspectable open var shadowsEnabled: Bool

Reload data

If you need to reload the data of the segmented control, simply call:

segmentedControl.reloadData()

Author

This library has been adapted for Swift 3.0+ by Sasho Jadrovski, http://jadrovski.com. The original creators are LunApps, as stated above.

License

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

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].