iOS: UILabel & UIButton in a table cell
I am trying to display a Label and a button开发者_开发问答 side-by-side in a UITableViewCell. The button sits at the right end & the Label sits at the left end. The label can host a long text and should get truncated if the text would flow out of bounds (I do not want to reduce the font size, etc.). Needless to say, I want this to work for both the orientations.
If I use UITableViewCellStyleDefault (without adding a button) & set a long text for the default label, I observe that the label auto-resizes perfectly when the orientation changes. Most probably because its autoresizingMask is set to UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleRightMargin.
Now, the way I see it, I could insert my button, and make the label truncate properly, if I could configure the value of the right margin that is being used by default (to accommodate the button). I essentially want it to auto-resize within the bounds that I specify. Is there a way this can be accomplished?
I would not prefer listening to each orientation change and setting the bounds of the label's frame. Any other feasible solution?
I finally went with subclassing UITableViewCell
& overriding layoutSubViews
. Thanks Mark!
精彩评论