我相信四舍五入发生在iOS的某个地方,因为标签会适合(一行,然后在...的末尾),如果将有0.75pt多的空间。所以它吸引了它,但由于缺少0.75pt空间而被切断。
现在我采取了以下方法:计算第二个标签(应该是关于一行的引用文本)是否适合父视图?如果不隐藏它。我只有在C#代码,但你应该得到的想法:
public override void LayoutSubviews()
{
base.LayoutSubviews();
NSString referenceTextToMeasure = new NSString ("Lorem ipsum dolor sit amet.");
// take the font of the description label which was cut off
CGRect referenceTextRect = referenceTextToMeasure.GetBoundingRect (
new CGSize(this.Frame.Width, nfloat.MaxValue),
NSStringDrawingOptions.UsesLineFragmentOrigin,
new UIStringAttributes() { Font = descriptionLabelFont },
new NSStringDrawingContext()
);
// 5 is the spacing constraint I have on the top
if ((this.Frame.Height - TitleLabel.Frame.Height - 5) < referenceTextRect.Height)
DescriptionLabel.Hidden = true;
}
似乎工作得很好,但一个完整的测试必须进行。你也可以使用固定的高度来代替referenceTextRect.Height,你可以节省一些计算。不过,我使用的方式允许调整字体,以便动态计算所有内容。
薰衣草色是包含2个标签的视图? –
@Bhavin:是的,它包含两个标签。 – testing
好的......和它的固定高度视图? –