I have UISegmentedcontrol(with two segments) and a UIView. Due to the fact that the minimum number of segments is 2, I will not hide segmentedcontroland add UILabel.
Here's what it looks like in a simulator:
(Red - UIView.)
Here is my code:
[self.segment setHidden:YES];
CGRect segmentFrame = self.segment.frame;
segmentFrame.size.width /= 2;
UILabel *myLabel= [[UILabel alloc] initWithFrame:segmentFrame];
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:1 inSection:0];
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
[cell.contentView addSubview:myLabel];
As you can see in the picture above, I use auto-layout. When it is viewhidden and added label, it viewdoes not move to the left. Therefore, I tried to move it programmatically (which probably should not be done when applying automatic layout):
CGRect myViewFrame = self.myView.frame;
myViewFrame.origin.x -= segmentFrame.size.width;
self.myView.frame = myViewFrame;
It still didn't work. My question is: how can I make it viewmove to the left when it is hiding segmentedcontrol?