I have a UISegmentedcontrol
(with 2 segments), and a UIView
. Due to the fact that the minimum number of segments is 2, I wan't to hide the segmentedcontrol
and add a UILabel
.
This is what it looks like in the simulator:
(The red is the
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 at the picture above, I have auto-layout applied. When the view
get's hidden and the label
gets added, the view
doesn't get moved over to the left. So I tried moving it programmatically (which probably shouldn't be done when auto-layout is applied):
CGRect myViewFrame = self.myView.frame;
myViewFrame.origin.x -= segmentFrame.size.width;
self.myView.frame = myViewFrame;
That still didn't work. My question is: How can I get the view
to move over to the left when the segmentedcontrol
becomes hidden?