Why are my UISegmentControl segments highlighting in iOS 8 when I have set background images for all states?

前端 未结 2 1455
一生所求
一生所求 2021-01-02 07:47

In iOS 6/7, I have used UISegmentedControl with background images to create an effect like so:

\"Cu

相关标签:
2条回答
  • 2021-01-02 07:57

    The reason the segment turns grey on selecting an already selected segment is because the segmented control is missing the state for selected and highlighted at the same time.

    In your case calling:

    [self.segmentedControl setBackgroundImage:segmentedControlBackgroundSelectedImage forState:UIControlStateSelected | UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
    

    should fix that problem.

    when you change your selection, the cell you tapped turns gray until the transition completes

    I couldn't reproduce that one, but perhaps this will fix both issues.

    0 讨论(0)
  • 2021-01-02 08:10

    Just in case, in Swift that would be (UPD for Swift 4)

    segmentedControl.setBackgroundImage(image, forState: .selected, barMetrics:.Default)

    segmentedControl.setBackgroundImage(image, forState: .highlighted, barMetrics:.Default)

    0 讨论(0)
提交回复
热议问题