objective c - AutoLayout does not work properly on ios 8.3

I am trying to add the facebook button.

Since you cannot drag and drop facebook button from the interface builder, you need to do programatically.

I add a dummy button with no text and try to assign its constraints to facebook button. It works on the 10.1 simulator, but when I test on 8.3 simulator it does not. I wonder what i am doing wrong?

- (void)viewDidLoad
{
    [super viewDidLoad];
    facebookLoginButton = [[FBSDKLoginButton alloc] init];
    [self.view addSubview:facebookLoginButton];
}

-(void)viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];
    facebookLoginButton.frame = dummyButton.frame;
}

ios 8.3 shows the facebook login button at the origin of the screen

enter image description here

ios 10.1 shows the facebook login button exactly on the right button which matches dummy button position.

enter image description here

1 Answer

  1. Aaron- Reply

    2019-11-16

    Setting an object's frame directly isn't using auto layout. Auto layout uses constraints, and adding a view programatically will result in implicit constraints being added unless you set translatesAutoResizingMaskIntoConstraints to false.

    Auto layout will override the frame the next time it recomputes the layout.

    However, you can easily add the button in Interface Builder directly; FBSDKLoginButton inherits from FBSDKButton which inherits from UIButton.

    You can simply add a UIButton in Interface Builder and then set its custom class to FBSDKLoginButton

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>