简体   繁体   中英

UIButton changing position doesn't work

I have a problem with changing the position of a UIButton, created in Interface Builder. I have an Outlet to it in one of my classes. Now I need to change the position of this button according to a User Default, saved in standard User defaults. The problem is, that the button's position won't change after calling this code:

self.planButton.center = CGPointMake(244, 234);

I have already tried to call [self.planButton setNeedsDisplay]

I have also tried to call [self.view reloadInputViews] with no effect.

Thanks for your help

You should use setFrame

[self.planButton setFrame:CGRectMake(244, 234, self.planButton.frame.size.width, self.planButton.frame.size.height)];

EDIT:

try this

self.view.autoresizesSubviews = NO;

If that doesn't work, You might want to do this in

(void)viewDidLayoutSubviews instead of viewDidLoad or viewDidAppear

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM