I have a button that was created to show Album Artwork in my app. The problem is how do I get this button to stay in the same area of the screen with different devices? All my other buttons are created with Auto Layout in Interface Builder.
As I mentioned in another post "how do I set a UIImageView to Safe Area Guides in C", the answer is that you create the UIButton in the normal manner with "initWithFrame: CGRectMake ( )". You add your constraints latter after the button has already been created.
< UIButton *yourbuttonItem = [[UIButton alloc] initWithFrame: CGRectMake (0, 0, 30, 30)];
yourbuttonItem.backgroundColor= [UIColor greenColor];
yourbuttonItem.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:yourbuttonItem];
[[yourbuttonItem.rightAnchor constraintEqualToAnchor:self.view.rightAnchor constant:-7] setActive:YES];
[[yourbuttonItem.bottomAnchor constraintEqualToAnchor:self.view.safeAreaLayoutGuide.bottomAnchor constant:-10] setActive:YES];
[yourbuttonItem setBackgroundImage: buttonImage forState: UIControlStateNormal];
[self.view addSubview:yourbuttonItem];
[yourbuttonItem setEnabled: YES]; >
Hope this helps!!