GocePetrovski / ScrollableSegmentedControl

Scrollable Segmented Control for when UISegmentedControl is not sufficient
MIT License
245 stars 74 forks source link

Can't able to change font size #43

Open SathiyakumarIOS opened 5 years ago

SathiyakumarIOS commented 5 years ago

When I try to set font size manually as like you have mentioned but no luck. Please come up with solution ASAP.

My code,

let largerRedTextAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20), NSAttributedStringKey.foregroundColor: UIColor.white] let largerRedTextHighlightAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20), NSAttributedStringKey.foregroundColor: UIColor.white] let largerRedTextSelectAttributes = [NSAttributedStringKey.font: UIFont.systemFont(ofSize: 20), NSAttributedStringKey.foregroundColor: UIColor.white]

segmentedControl.setTitleTextAttributes(largerRedTextAttributes, for: .normal) segmentedControl.setTitleTextAttributes(largerRedTextHighlightAttributes, for: .highlighted) segmentedControl.setTitleTextAttributes(largerRedTextSelectAttributes, for: .selected)

Mithsen commented 4 years ago

Try this workaround, this worked for me. (note: change the font size in didload)

override func viewDidAppear(_ animated: Bool) {
        let lastSegmantNo = segmentedControl.numberOfSegments-1
        let lastTitle = segmentedControl.titleForSegment(at: lastSegmantNo) ?? ""

        if(segmentedControl.selectedSegmentIndex == lastSegmantNo) {
            segmentedControl.removeSegment(at: lastSegmantNo)
            segmentedControl.insertSegment(withTitle:lastTitle , at: lastSegmantNo)
            segmentedControl.selectedSegmentIndex = lastSegmantNo
        } else {
            segmentedControl.removeSegment(at: lastSegmantNo)
            segmentedControl.insertSegment(withTitle:lastTitle , at: lastSegmantNo)
        }
    }