IOS Software Center Objects

I am updating the app to support iPhone 6 Plus. In one of the views, which are programmatically configured, running on 5S or lower has all views oriented the way they should be. However, on the 6 Plus, it accelerates slightly to the left. How can I tweak this code to keep it horizontal across all versions?

[self.logInView.usernameField setFrame:CGRectMake(35.0f, 125.0f, 250.0f, 50.0f)];
[self.logInView.passwordField setFrame:CGRectMake(35.0f, 175.0f, 250.0f, 50.0f)];
[self.fieldsBackground setFrame:CGRectMake(35.0f, 125.0f, 250.0f, 100.0f)];
[self.logInView.logInButton setFrame:CGRectMake(35.0f, 235.0f, 250.0f, 40.0f)];

      

+3


source to share


4 answers


[self.logInView.usernameField setFrame:CGRectMake(self.view.center.x - 125, 0, 250.0f, 50.0f);];
[self.logInView.passwordField setFrame:CGRectMake(self.view.center.x - 125, 175.0f, 250.0f, 50.0f)];
[self.fieldsBackground setFrame:CGRectMake(self.view.center.x - 125, 125.0f, 250.0f, 100.0f)];
[self.logInView.logInButton setFrame:CGRectMake(self.view.center.x - 125, 235.0f, 250.0f, 40.0f)];

      



you can use this code to get horizontal horizontal line on all iOS devices.

+3


source


The answer is simple ... Use autorun. But if you don't know how to use it, try this:

First, create some definitions:

#define IS_IPHONE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
#define IS_IPADDEVICE (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
#define IS_IPHONE_4 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 480.0)
#define IS_IPHONE_5 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 568.0)
#define IS_IPHONE_6 (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 667.0)
#define IS_IPHONE_6_PLUS (IS_IPHONE && [[UIScreen mainScreen] bounds].size.height == 736.0)
#define IS_IPAD (IS_IPADDEVICE && [[UIScreen mainScreen] bounds].size.height == 1024.0)

      

Then create a simple if statement:



   if (IS_IPHONE_4) {
        // iPhone 4
    } else if (IS_IPHONE_5) {
        // iPhone 5
    } else if (IS_IPHONE_6) {
        // iPhone 6
    } else if (IS_IPHONE_6_PLUS) {
        // iPhone 6 plus
    } else if (IS_IPAD) {
        // iPad
    } else {
        // other device
    }

      

If I want to center an object, I use the method frame

:

theobject.frame = CGRectMake((theobject.frame.size.width/2) - (theobject.image.size.width/2), 20, theobject.image.size.width, theobject.image.size.height);

      

I hope this answer helps you!;)

+1


source


You seem to be updating your Parse loginView . I had the same problems ... It's a real pain to get the default loginView to fit all screen device sizes. I'll share some code that I hope will help. It should be on the IOS User Assistant page. Put this in your .m file

- (void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

//Returns the screen dimensions (in points) of the user current device
CGRect screenBounds = [[UIScreen mainScreen] bounds];


//Finds to see if the user has an iPhone 4s, and then set the layout if they do
if(screenBounds.size.height==480)
{
    [self.logInView.logInButton setFrame:CGRectMake(self.view.center.x - 125, 300.0f, 250.0f, 50.0f)];
    [self.logInView.usernameField setFrame:CGRectMake(self.view.center.x - 125, 165.0f, 250.0f, 50.0f)];
    [self.logInView.passwordField setFrame:CGRectMake(self.view.center.x - 125, 215.0f, 250.0f, 50.0f)];
    [self.logInView.passwordForgottenButton setFrame:CGRectMake(self.view.center.x - 125, 265.0f, 250.0f, 40.0f)];    }


//Finds to see if the user has an iPhone 5/5s, and then set the layout if they do
else if (screenBounds.size.height == 568)
{
    [self.logInView.logInButton setFrame:CGRectMake(self.view.center.x - 125,360.0f, 250.0f, 50.0f)];
    [self.logInView.usernameField setFrame:CGRectMake(self.view.center.x - 125, 245.0f, 250.0f, 50.0f)];
    [self.logInView.passwordField setFrame:CGRectMake(self.view.center.x - 125, 295.0f, 250.0f, 50.0f)];
    [self.logInView.passwordForgottenButton setFrame:CGRectMake(self.view.center.x - 125, 445.0f, 250.0f, 40.0f)];    }

//If the user doesn't have a 4S/5/5s, then they must be using an iPhone 6/6+
else {

        [self.logInView.logInButton setFrame:CGRectMake(self.view.center.x - 125, 420.0f, 250.0f, 50.0f)];
        [self.logInView.usernameField setFrame:CGRectMake(self.view.center.x - 125, 275.0f, 250.0f, 50.0f)];
        [self.logInView.passwordField setFrame:CGRectMake(self.view.center.x - 125, 325.0f, 250.0f, 50.0f)];
        [self.logInView.passwordForgottenButton setFrame:CGRectMake(self.view.center.x - 125, 485.0f, 250.0f, 40.0f)];

//Prints out the current device being used
    NSLog(@"Current device: %@", [[UIDevice currentDevice] model] );
}

      

0


source


you can use "borders" and "center":

self.logInView.usernameField.bounds = CGRectMake(0,0,250,50);
self.logInView.usernameField.center = CGPointMake(160, 150);

      

-3


source







All Articles