Customizing Left & Right UISegmentedControl Buttons

前端 未结 3 886
执念已碎
执念已碎 2020-12-12 10:25

I\'m trying to customize the following segmented control, using a left image for the first button and a right image for the second button. How would I do this using UIAppear

3条回答
  •  时光说笑
    2020-12-12 10:43

    You need to make one background image that is for all your segments, and also an image that is just the left edge of a button, an image that is the join between two buttons, and an image that is the right edge. Some of those need to be done for multiple states. So here is your image list:

    • left cap, selected
    • left cap, unselected
    • segment background, selected
    • segment background, unselected
    • right cap, selected
    • right cap, unselected
    • middle cap, left selected right unselected
    • middle cap, left unselected, right selected
    • middle cap, both selected
    • middle cap, both unselected

    For the middle caps you can put them in like this: (text from Apple docs).

    // Image between two unselected segments.
    [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
                  rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
    // Image between segment selected on the left and unselected on the right.
    [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateSelected
                  rightSegmentState:UIControlStateNormal barMetrics:barMetrics];
    // Image between segment selected on the right and unselected on the right.
    [mySegmentedControl setDividerImage:image1 forLeftSegmentState:UIControlStateNormal
                  rightSegmentState:UIControlStateSelected barMetrics:barMetrics];
    

    If you're using UIAppearance, obviously you'd send those messages to the appearance proxy.

提交回复
热议问题