objective c - Size a UIToolbar to fit its items? -
i'm trying figure out clean way make uitoolbar
wide needs to fit items contains. there way either:
- configure
uitoolbar
adjust width automatically items changed? - programatically determine minimum width required items, can used set
uitoolbar
's frame?
i haven't been able figure out due spacing between items , fact uibarbuttonitem
s not uiview
subclasses.
after trying suggestions other answers did not work unless used custom views, or unless loaded, arrived @ way set toolbar width based on items:
//add bar items toolbar first. uiview* v = toolbar.subviews.lastobject; float newwidth = v.frame.origin.x + v.frame.size.width; //set toolbar width
you'll need override uitoolbar -setitems:
or otherwise detect changed buttons autoresize.
i have included feature in refactoring library, es_ios_utils, set navigation item's right item multiple buttons. in preceding link, see uitoolbar +toolbarwithitems:
, uinavigationitem -setrightbarbuttonitems
.
Comments
Post a Comment