Skip to content

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

Open
@jackngai

Description

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.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions