简体   繁体   English

UIButton更改位置不起作用

[英]UIButton changing position doesn't work

I have a problem with changing the position of a UIButton, created in Interface Builder. 我在更改在Interface Builder中创建的UIButton的位置时遇到问题。 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] 我已经尝试调用[self.planButton setNeedsDisplay]

I have also tried to call [self.view reloadInputViews] with no effect. 我也曾尝试调用[self.view reloadInputViews]没有任何效果。

Thanks for your help 谢谢你的帮助

You should use setFrame 您应该使用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 (void)viewDidLayoutSubviews而不是viewDidLoadviewDidAppear

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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