0

I created a text box by code in Xcode, by giving

if (isLandScape) {
    textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(800, 10, 200, 30)];
}
else {
    textFieldRounded = [[UITextField alloc] initWithFrame:CGRectMake(550, 10, 200, 30)];
}

but when rotated, two box are created, I dont want this, what is the treatment for my code?

Vignesh
  • 10,205
  • 2
  • 35
  • 73
Pawriwes
  • 283
  • 1
  • 6
  • 21

1 Answers1

1
  1. Take a look at autoresizingMask property.
  2. In what method are you creating this view?
Denis Mikhaylov
  • 2,035
  • 21
  • 24
  • @denish i tried to follow this link http://stackoverflow.com/questions/843683/cocoa-nsview-changing-autosizing-properties but xcode doesnot recognise the NSView, i think that is not for IOS, I am new to autoresizingMask and I am calling this method from shouldAutorotateToInterfaceOrientation method. – Pawriwes Apr 18 '12 at 06:41
  • 1
    in your case authoresizingMask should be UIViewAutoresizingFlexibleLeftMargin hence you are adjusting you x of frame. So in viewDidLoad: 1. Choose appropriate frame for current orientation 2. Create UItextField 3. Set autoresizingMask = UIViewAutoresizingFlexibleLeftMargin Now all rotation frame adjustments will be made automatically – Denis Mikhaylov Apr 18 '12 at 06:50