Changing CGRectMake (x, x, x, x) to another location, such as (y, y, y, y)

I placed the button in my view using CGRectMake (x, x, x, x), x is the location and size of the course. When I rotate the view using - (BOOL) shouldAutoRotate ... I want to change the location of the button, starting from the center in portrait mode and ending with the center in landscape mode. The button contains information on the label that the user sets, so I DO NOT want to use a different view for landscape orientation. What if they set something in the portrait and rotate to a horizontal position? They will lose their data. So my question is: how do I move something that was previously installed? See the code below, I do not want to reuse the button. Thank!

// DATE

lblDate = [[UILabel  alloc] initWithFrame:CGRectMake(x, y, width, height)];

lblDate.text = @"Date:";
lblDate.backgroundColor = [UIColor clearColor];
[contentView addSubview:lblDate];
+5
source share
3 answers

Just set the frame to the new Rect, for example

lblDate.frame = CGRectMake(x,y,width,height);
+14
source

lblDate.frame = newRect

But you should probably use auto-save flags for this.

0
source

UIView.

, .

@property () CGRect frame . . , . .

. transform , undefined .

drawRect:. drawRect: , , contentMode UIViewContentModeRedraw.

Changes to this property can be animated. However, if the transform property contains a non-identical transform, the value of the frame property is undefined and should not be changed. In this case, you can move the view using the center of the property and adjust the size using bounds.

0
source

All Articles