Giter Site home page Giter Site logo

sasojadrovski / sjfluidsegmentedcontrol Goto Github PK

View Code? Open in Web Editor NEW
971.0 22.0 76.0 12.51 MB

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

License: MIT License

Ruby 1.69% Swift 98.31%
segmented-controls segmentedcontrol segment animated ios swift uisegmentedcontrol control

sjfluidsegmentedcontrol's People

Contributors

ivkosh avatar maxhuk avatar sasojadrovski 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

sjfluidsegmentedcontrol's Issues

Delegate function not being updated if swiped/scrolled to quickly.

Hello and thanks for the great work you've done on the project. I'm facing an issue where the delegate method is not being called when the selected index is changed via a swipe. I'm monitoring via the following delegate method segmentedControl(_ segmentedControl: SJFluidSegmentedControl, didChangeFromSegmentAtIndex fromIndex: Int, toSegmentAtIndex toIndex:Int) and it appears that if the user scrolls quickly to a new segment index this is not called as the toIndex is not updated.

Is there another delegate function I should be monitoring for this or is it unexpected behavior? I really like the project here and will be using it in my app if I can resolve this.

Thanks for taking the time to read/respond.

Make datasource and delegate to be of the correct type.

Currently, both the datasource property and the delegate property are of type AnyObject?. Why not change them to be of type SJFluidSegmentedControlDatasource? and SJFluidSegmentedControlDelegate? respectively? This way errors can be detected at compile time.

Swift4

Add supported to Swift4

Programmatically change segment index

Hi, thanks for great lib :) I have a few questions.
Is it possible to change the selected segment programmatically, and if yes, how can I do that?

And my second question is:
is it possible not to have any index selected at all? Say, set the index to -1?

Thanks

ReloadData() removes colour

Hello,

I'm using NightNight to support a day and night theme of my app. For this, I subscribe to a Notification of NightNight, which informs me when the user changes the theme.

Inside the method being called I merely say secondSwitch.reloadData()

This secondSwitch has two segments: index 0 is always grey, index 1 is blue or orange, depending on the theme.
There's also a firstSwitch which shows none of the following problems!

Whenever I update the theme, the notification fires, and the following happens:

If segment at index 1 is currently selected, it switches from blue to orange or vice versa as it should!
If segment at index 0 is currently selected, it should simply stay grey. However it loses any colour! It simply gets clear/transparent. If I grab the thumb of the control and start to drag, it reappears grey! Also switching it and switching it back shows the proper colour.

Here's my delegate method:

`if segmentedControl.tag == 0 {

switch index {
    case 1:
    
        return [FlatYellow(), FlatYellowDark()]
    case 2:
        
        return [FlatNavyBlue(), FlatNavyBlueDark()]
    default:
        
        return [FlatSkyBlue()]
}

}
else if segmentedControl.tag == 1 {

switch index {
    case 1:
    
        if NightNight.theme == .normal {
            
            return [FlatSkyBlue()]
        }
        
        return [FlatOrange()]

    default:
        
        return [FlatGrayDark()]
}

}

return [FlatSkyBlue()]
`

Here, secondSwitch has the tag 1, whilst firstSwitch has the tag 0.

I'd highly appreciate any tips as to what I do wrong! Thanks!

What can I use to change container views?

I have 3 container view and I want to connect these and SJFluidSegmentedControl. I've tried this
if segmentedControl.currentSegment == 0 { firstContainerView.alpha = 1 secondContainerView.alpha = 2 // bla bla bla }
But it didn't work. Can you suggest me a place and method of use ?

The right most segment in a 3 segment control appears lighter/faded?

Hi,

I noticed something strange with the segment control I created programmatially with SJFluidSegmentedControl. The third segment appears faded/lighter in color than the 2nd segment. Please see screenshot below.

screen shot 2017-09-07 at 12 11 07 pm

When I select a different segment (2nd or 3rd) and then go back to the first segment, the third segment is no longer faded. I was trying to troubleshoot this and noticed changing the transition style from .fade (default) to .none will cause the 2nd segment to also look faded and selecting different segments will not correct the problem. But how can I correct this issue so the 3rd segment shows up correctly when the view is loaded?

screen shot 2017-09-07 at 12 15 35 pm

Here is my code:

//
//  ViewController.swift
//  TestSJFluidSegmentedControl
//
//  Created by Jack Ngai on 9/7/17.
//  Copyright ยฉ 2017 Jack Ngai. All rights reserved.
//

import UIKit
import SJFluidSegmentedControl


class ViewController: UIViewController, SJFluidSegmentedControlDelegate, SJFluidSegmentedControlDataSource {
    
    lazy var mySegmentControl:SJFluidSegmentedControl = {
        [unowned self] in
        let segmentControl = SJFluidSegmentedControl(frame: CGRect(x: 50, y: 100, width: 300, height: 50))
        segmentControl.dataSource = self
        segmentControl.delegate = self
        segmentControl.backgroundColor = UIColor(red:0.85, green:0.85, blue:0.85, alpha:0.2)
        segmentControl.textColor = UIColor.red
        segmentControl.transitionStyle = .fade // Changing to .none will make all other segments look faded, .slide has is the same as .fade
        segmentControl.textFont = UIFont(name: "Montserrat-Regular", size: 12) ?? UIFont.systemFont(ofSize: 12)
        segmentControl.cornerRadius = 10
        segmentControl.shadowsEnabled = false
        segmentControl.shapeStyle = .roundedRect
        return segmentControl
    }()
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        view.addSubview(mySegmentControl)
        //mySegmentControl.translatesAutoresizingMaskIntoConstraints = false
        
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


    func numberOfSegmentsInSegmentedControl(_ segmentedControl: SJFluidSegmentedControl) -> Int {
        return 3
    }
    
    func segmentedControl(_ segmentedControl: SJFluidSegmentedControl, titleForSegmentAtIndex index: Int) -> String? {
        switch index{
        case 0:
            return "THIS WEEK"
        case 1:
            return "THIS MONTH"
        case 2:
            return "THIS YEAR"
        default:
            return ""
        }
    }
    
    func segmentedControl(_ segmentedControl: SJFluidSegmentedControl, gradientColorsForSelectedSegmentAtIndex index: Int) -> [UIColor] {
        return [UIColor.red]
    }
    
}

Thanks for taking the time to read my question.

iOS8 not be supported!

Your code is wonderful. Would you mind to support iOS8 ? Because many application must still support iOS8

Setting current segment index in viewDidLoad

Hi,
I have tried setting the current segment index to some other value than 0 in viewDidLoad but the segment just remains at the first position. Same in viewWillAppear.

If I call the following line inside viewDidAppear, the segment switches to the correct position
segmentedControl.setCurrentSegmentIndex(startingSegment, animated: false)
If, however I make the above call in viewDidLoad or viewWillAppear or the following call anywhere, the segments just don't change

tabBarControl.currentSegment = startingSegment

My question is, how can I make a segment change be effective from viewDidLoad or viewWillAppear, so that there will be no visible transitioning of segment positions?

(Bug) Third label displayed always in white at first launch.

First of all, thank you fort his incredible library.
There's a very small bug which displays the third (the first and the second work fine) label (in your example it's the word "IT") always in white, at the first launch.
After switching the tabs, it displays correctly in the color set in the Inspector View.

Hope to see the bug solved soon!
Again, thank you so much!

Overlapping accesses to 'colors'

I'm getting the following error:

Overlapping accesses to 'colors', but modification requires exclusive access; consider copying to a local variable

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.