根据ios中标签文本的按钮动态定位

问题描述 投票:1回答:4

我已在标签下贴了一个标签和两个按钮。我想根据标签中的文本动态向上和向下移动按钮。As in the image I have a label and three line data within it.and two Button below it

in this image I have data in single line in label then button should be shift upward accordingly

ios objective-c iphone xcode6
4个回答
1
投票
    CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);

CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];   

//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;

1
投票
CGSize maximumLabelSize = CGSizeMake(296, FLT_MAX);

CGSize expectedLabelSize = [yourString sizeWithFont:yourLabel.font constrainedToSize:maximumLabelSize lineBreakMode:yourLabel.lineBreakMode];   

//adjust the label the the new height.
CGRect newFrame = yourLabel.frame;
newFrame.size.height = expectedLabelSize.height;
yourLabel.frame = newFrame;

根据标签的高度设置按钮的边框


0
投票

而不是硬编码,请使用自动版式。

Set Accept button left edge constraint to label left edge constraint.
Set Decline button right edge constraint to label right edge constraint. 
Add vertical space between buttons and label.

Take label height constraint reference and set it's constant at runtime which is equal to label height.

0
投票

与:一起使用

用于接受按钮:

btnAccept!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)

对于下降按钮:

btnDecline!.frame = CGRectMake(CGRectGetMinX(txtView!.frame), CGRectGetMaxY(txtView!.frame) + 20, btnAccept!.frame.size.width, btnAccept!.frame.size.height)

变量btnAccept是接受按钮

变量btnDecline是拒绝按钮

变量txtView是textview

© www.soinside.com 2019 - 2024. All rights reserved.