简体   繁体   中英

How to rearrange objects in UITableViewCell after rotating?

I have 3 objects in a cell. They are UILable with text (at left), another UILable with text (at right) and a UIButton (at right most). Like:

[[label1_ _ ___ ][label2][button]]

Now how to rearrange these objects after rotating if i want just label1 to stretch and label2 with the button should stay with their original size and right aligned? Like

[[label1_ _ __ _ __ _ __ _ __ _ ____ ][label2][button]]

Is there any align options to align button and label2 right (one by one) and label1 left to make only label1.autoresizingMask = UIViewAutoresizingFlexibleWidth?
I'm trying to do it (fill the cell with subviews) programmatically and I use

[cell.contentView addSubview:subview]

For my left label i did:

 label1.autoresizingMask = UIViewAutoresizingFlexibleWidth;

But after rotating from portrait to landscape I get no changes and it looks like:

[[label1_ _ __ _ ][label2][button] _ __ _ __ _ ____ ]

Is there any other UIView with property like UIBarButtonSystemItemFlexibleSpace?

In xib , using Interface Builder , use the Autoresizing property for lable and button , the red line's / Arrow's for autoresize when change orientation. so set top and rignt line only for second label2 and button.

otherwise , programatically , - change the co-ordinate in willAutorotate/shouldAutorotate delegate.

better way ,..using xib.

thanks Dipak C.

Are you creating this custom table view cell from a nib or programmatically? If you're doing it in a nib, make sure the top level object you dragged out was a UITableViewCell and that you set it's class to your custom subclass. If you are doing it programmatically, make sure you add the subviews to the cell's contentView and not to the cell itself. A cell doesn't really know how to resize its subviews appropriately when its size changes due to things like entering/exiting editing mode. Its contentView, however, does.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM