以编程方式在xib文件中移动UILabel [英] Programmatically moving a UILabel in a xib file

查看:43
本文介绍了以编程方式在xib文件中移动UILabel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题:我的UILabel在我更改其框架信息后没有移动,但是在使用NSLog输出后,该框架信息与正确的位置匹配,但是标签本身实际上并未移动.

Problem: My UILabel is not moving after I change its frame information but after outputing with NSLog the frame info matches the correct position, yet the label itself does not actually move.

更多信息::我正在尝试将UILabel移动到与UITextField相同的位置.两者都包含在XIB文件中.我可以很好地更新文本,并且输出框架信息将表明标签已移动到正确的位置,但是当您实际在屏幕上查看时,无论我手动将其放置在XIB文件中的位置,都可以看到该标签;它没有动.

More Info: I'm trying to move a UILabel to the same position as a UITextField. Both are contained in a XIB file. I can update the text just fine, and outputting frame information would indicate that the label has moved to the correct position but when you actually look on the screen you can see the label is exactly wherever I placed it in the XIB file manually; it hasn't moved.

photoDescriptionLabel 是我要放在 photoDescription 的UILabel上的UILabel,它是一个UITextField.文本字段变为不可见且可见,因此您只能看到标签,直到需要对其进行编辑为止,这时我才隐藏标签并使文本字段可见.

photoDescriptionLabel is the UILabel I am trying to place on-top of photoDescription which is a UITextField. The text field is made invisible and made visible so you only see the label until its time to edit it, at which time I hide the label and make the text field visible.

CODE -从相应的ViewController内部获取

CODE - Taken from inside corresponding ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.photoDescriptionLabel.frame = CGRectMake(self.photoDescription.frame.origin.x,self.photoDescription.frame.origin.y,self.photoDescriptionLabel.frame.size.width,self.photoDescriptionLabel.frame.size.height);        
    self.photoDescription.hidden = YES;
    self.photoDescriptionLabel.hidden = NO;
    NSLog(@"x: %f, y: %f, width: %f, height: %f ",self.photoDescriptionLabel.frame.origin.x,self.photoDescriptionLabel.frame.origin.y,self.photoDescriptionLabel.frame.size.width,self.photoDescriptionLabel.frame.size.height);        

}

推荐答案

我认为您必须在Interface Builder中关闭主视图的使用自动布局"标志.创建新项目时,默认情况下会启用自动布局".

I think you have to switch off the main view's "Use Autolayout" flag in Interface Builder. Auto Layout is enabled by default when you create a new project.

这篇关于以编程方式在xib文件中移动UILabel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆