ios - How to increase UISegmentedControl total width? -


to clear front, i'm not asking how modify width of individual uisegmentedcontrol segments, or buttons.

my end-goal create uisegmentedcontrol embedded in uiscrollview. uisegmentedcontrol have ability indefinitely increase number of segments.

to accomplish this, need increase total width of uisegmentcontrol itself, each time segment added. there way can increase total width without recreating brand new uisegmentedcontrol object each time add segment?

thank you, in advance!

@matthiasbauch's comment helped me track down whole solution, detailed below:

note: i'm using autolayout, anywhere use storyboard you'll have substitute programmatic equivalent.

1) first, drag "segmented control" out on the storyboard.
2) create outlet control added.
3) also, ctrl+click on control, , drag itself. click on "width" add width constraint.
4) now, open document outline (editor > "reveal document outline")
5) open "view" segmented control in, open dropdown segmented control (mine named "first, second" default). open "constraints".
6) ctrl+click on "width" constraint made , drag on view controller create outlet it. allow adjust width programmatically.

using article mentioned below, can update constraint follows (using animation...bonus!)

go method want use update width , following:

let desiredwidthchange = 30.0  self.widthconstraint.constant =      self.mysegmentedcontrol.constant + desiredwidthchange  self.mysegmentedcontrol.setneedsupdateconstraints()  uiview.animatewithduration(0.5, animations: { () -> void in     self.mysegmentedcontrol.layoutifneeded() // captures of frame changes.     println("width updated successfully") }) 

reference:
are nslayoutconstraints animatable?


Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -