sasojadrovski / sjfluidsegmentedcontrol Goto Github PK
View Code? Open in Web Editor NEWA segmented control with custom appearance and interactive animations. Written in Swift 3.0.
License: MIT License
A segmented control with custom appearance and interactive animations. Written in Swift 3.0.
License: MIT License
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 ?
I don't really understand what the gradient bounce color is. Where can I see it in the segmented control?
I'm getting the following error:
Overlapping accesses to 'colors', but modification requires exclusive access; consider copying to a local variable
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
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.
as in
@IBOutlet weak var segmentView1: SJFluidSegmentedControl!
@IBOutlet weak var segmentView2: SJFluidSegmentedControl1!
@IBOutlet weak var segmentView3: SJFluidSegmentedControl2!
for e.g. i can have 3 tables in one view similar to that..
if i check segmentedControl == self.segmentView1 ( it crashes with nil )
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!
How can I simply make the selected segment font bold? Please accept my apologies if my request does not hit nail on the head.
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.
Your code is wonderful. Would you mind to support iOS8 ? Because many application must still support iOS8
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!
I've been reading inside the code and was wondering if there was a way to change the shadow colour to another colour aside from that of the segment
Hi,
For iOS projets it's will be great to make your component Carthage compatible
Take a look at these articles:
On your README.md
add on top and add section for the installation with Carthage.
Hi, the fluid in selectedIndex when in portrait mode and landscape mode are not the same.
Add supported to Swift4
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.
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?
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.
Perhaps there could be a "noItemSelected"-ish setting, that initializes the view without any item selected?
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.