ios - UISegmentedControl (with images) in UITableViewCell (AutoLayout) always 29 points high -
standard tableview
app. autolayout. each (cell) class has own .xib file, no storyboard.
i have segmented control in tableview
cell filling (almost) completely, 4 edges bound 6 points space container (=content view of tableviewcell
). segments made images, not text.
i expect when call -[setimage: forsegmentatindex:]
control changes intrinsic content size make enough space segment images - view height. did set it's content hugging priority 251 (and cell's hugging priority stays @ default 250), when use narrow images segmented control height should shrink (and cell content view height also). , when use larger images segmented control height should grow... compute correct height measuring invisible reference cell (dequeued myself in -[viewdidload]
, kept in viewcontroller
property), asking autolayout -[systemlayoutsizefittingsize:uilayoutfittingcompressedsize]
reference cell's contentview. works fine, different sizes return in -[tableview heightforrowatindexpath]
different images. autolayout
computes height used correctly.
but real (visible) cell of tableview
doesn't change height of segmented control. stays @ 29 points (which standard height segmented control text labels , not images), no matter cellheight
being used , images set.
i tried add nslayoutconstraint
segmented control, set it's height:
heightconstraint = [nslayoutconstraint constraintwithitem:self attribute:nslayoutattributeheight relatedby:nslayoutrelationgreaterthanorequal toitem:nil attribute:nslayoutattributenotanattribute multiplier:1 constant:newheight];
and add (once) segmented control. got "unable simultaneously satisfy constraints" when tried nslayoutrelationequal
, that's why used nslayoutrelationgreaterthanorequal
. (probably computed newheight
value wrong). still doesn't work - 29 points , garbled images in segments...
what doing wrong? or ios bug uisegmentedcontrol
, autolayout
? of course revert manual layout , set frame of segmented control - i'd use autolayout
...
i found solution:
implement
-(cgsize)intrinsiccontentsize { cgsize size = cgsizemake(288, 68); return size; }
on segmentedcontrol subclass. well, of course compute height based on actual image height instead of using 68, works...
Comments
Post a Comment