sasojadrovski / SJFluidSegmentedControl

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

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

jackngai opened this issue · comments

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.

I noticed setting the current segment to the middle segment solves the problem, but it is a hack at best as I want the current segment to be the left most segment.

I need a solution for this problem too. Still no answer?