Note that there are some explanatory texts on larger screens.

plurals
  1. POChange UIView layout programmatically for iPhone 5
    primarykey
    data
    text
    <p>I am trying to change the layout of my UIView programmatically, and not by using Auto Layout, as I am trying to deploy this app for iOS 4 and up. I basically set my view up with the screen height at 455(iPhone 5)(I know the actual screen size is 568 points, but I have a tab bar on the bottom so I am assuming the size shown in IB has taken that into account). I recorded the origin of all of my buttons and labels relative to the longer screen size and programmatically changed them to how I preferred them. The problem is, some of the buttons and labels are going off the screen now, so I think I have to perform some kind of conversion to keep them in bounds, but I am not sure what. See the pictures attached below:</p> <p>Image before my initMethod is called to change button and label origins <img src="https://i.stack.imgur.com/fZaPX.png" alt=""> Image after my initMethod is called to change the origin <img src="https://i.stack.imgur.com/TYJm6.png" alt=""> View properties in XCode for the old screen size <img src="https://i.stack.imgur.com/j0BdP.png" alt=""> This is how I want the view to Look. I moved the buttons around and recorded the origin of each. <img src="https://i.stack.imgur.com/6rBIj.png" alt="enter image description here"> Picture of my init method in viewWillAppear. Notice how the frame of the label is zero. <img src="https://i.stack.imgur.com/q66Ej.png" alt="enter image description here"> Here is the code I used:</p> <pre><code>-(void)initView { CGRect screenBounds = [[UIScreen mainScreen] bounds]; if (screenBounds.size.height == 480) { //iphone 4,4s //done }else if(screenBounds.size.height == 568) { //iphone 5 CGRect frame; //Static Professor label frame = [staticProfessorLabel frame]; frame.origin.x = 48; frame.origin.y = 218; [staticProfessorLabel setFrame:frame]; //Professor Label frame = [professorLabel frame]; frame.origin.x = 192; frame.origin.y = 218; [professorLabel setFrame:frame]; //show button frame = [showProfessorButton frame]; frame.origin.x = 67; frame.origin.y = 258; [showProfessorButton setFrame:frame]; //clear proff button frame = [clearProfessor frame]; frame.origin.x = 240; frame.origin.y = 258; //note label frame = [bottomNote frame]; frame.origin.x = 160; frame.origin.y = 310; [bottomNote setFrame:frame]; //search button frame = [searchButton frame]; frame.origin.x = 158; frame.origin.y = 424; [searchButton setFrame:frame]; //spinner frame = [actIndicator frame]; frame.origin.x = 266; frame.origin.y = 424; [actIndicator setFrame:frame]; } } </code></pre> <p>Also, I am calling this in the viewDidAppear method because when I call it in viewDidLoad, none of the buttons and labels give me a valid frame(I am guessing they are not initialized yet).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload