Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIButton Changing Position

I have a button set up in IB. I have an IBOutlet set up and the onscreen object linked to it. Is there a way to programmatically change that buttons position and/or size? I know you can change the title and some things but I don't see how to change it's position or size.

enter image description here

Now I would like to change the position of it accordingly. Is it possible? If yes, please let me know how, since I am trying to change the position of my button in the following code, but it does not work in the header file.

@property (nonatomic, strong) IBOutlet UIButton *mybuttonOutlet;

In the implementation file:

-(void)viewDidLoad {


    screenSizeHeight=[UIScreen mainScreen].bounds.size.height;


if(screenSizeHeight==568)

    mybuttonOutlet.frame= CGRect(38, 464 ,157,25);


if(screenSizeHeight==480)

    mybuttonOutlet.frame= CGRect(38, 364 ,157,25);

}
like image 301
casillas Avatar asked May 06 '13 19:05

casillas


2 Answers

Remove Use Autolayout from the button in IB or storyboard.

like image 189
Retterdesdialogs Avatar answered Oct 20 '22 15:10

Retterdesdialogs


If you want to adjust positions with Autolayout enabled, you will have to change your code like this

-(void)viewDidLayoutSubviews {

    screenSizeHeight=[UIScreen mainScreen].bounds.size.height;

    if(screenSizeHeight==568)
        mybuttonOutlet.frame= CGRect(38, 464 ,157,25);

    if(screenSizeHeight==480)
        mybuttonOutlet.frame= CGRect(38, 364 ,157,25);
}

Basically you need to perform any custom layout adjustments in viewDidLayoutSubviews method if Autolayout is enabled

like image 43
user1988 Avatar answered Oct 20 '22 14:10

user1988