How can I enable multiple segments of a UISegmentedControl to be selected?

后端 未结 6 1576
太阳男子
太阳男子 2021-01-04 06:44

Lets say my UISegmentedControl has 8 numbered segments. I would like for the user to be able to turn on 2, 3, or more of them at once. Toggling them. Essentially like a bits

6条回答
  •  被撕碎了的回忆
    2021-01-04 07:08

    Answer for those who will come here from Google: it's now possible to change the behaviour of a UISegmentedControl. Go to Inspector -> Mode -> Select Any instead of Select One. To find out which segments are selected I suggest to create a function like this one:

    extension UISegmentedControl {
        func getBarState() -> [Bool] {
            var states: [Bool] = []
            for i in 0..

    As Google brought me here while searching for the OSX version I'll also post a working solution for NSSegmentedControl:

    extension NSSegmentedControl {
        func getBarState() -> [Bool] {
            var states: [Bool] = []
            for i in 0..

提交回复
热议问题