简体   繁体   English

uilabel文本更改后,移动uiview

[英]Move uiview once uilabel text has changed

I have a UIlabel that when a user clicks a button its text changes, this label is then resized using: 我有一个UIlabel,当用户单击按钮时,其文本会更改,然后使用以下命令调整此标签的大小:

CGRect frame = label.frame;
    [label sizeToFit];
    frame.size.height = label.frame.size.height;
    label.frame = frame;

So that the width is kept the same but the height of the label is changed so all text fits in this. 因此宽度保持不变,但标签的高度却改变了,因此所有文本都适合于此。

I then however need the uiview below this label to be moved down so that it starts at the bottom of the label, how do I do this? 但是,我然后需要向下移动该标签下面的uiview,以便它从标签的底部开始,我该怎么做?

Worked it out in the end by doing: 最后通过执行以下操作来解决:

    CGRect contentframe = _lbl_content.frame; //the uilabel
    CGRect keyframe = _view_keystuff.frame; //the uiview
    float startlocation = contentframe.origin.y;
    startlocation += contentframe.size.height;
    keyframe.origin.y = startlocation;
    _view_keystuff.frame = keyframe;

You just want to put the UIView below the label? 您只想将UIView放在标签下方?

Try this: 尝试这个:

UIView *viewBelowLabel = [[UIView alloc] init];

viewBelowLabel.frame = CGRectMake( "your view origin x", label.frame.origin.y + label.frame.size.height, "your view size width", "your view size height");

You should adjust UIView frame after the resizing of the label 调整标签大小后,应调整UIView框架

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

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