iOS 7 sizeWithAttributes: replacement for sizeWithFont:constrainedToSize

前端 未结 9 1642
执笔经年
执笔经年 2020-11-28 01:31

How do you return a multiline text CGSize from the new iOS 7 method sizeWithAttributes?

I would like this to produce the same results as sizeWithFont:constrainedToSi

9条回答
  •  醉酒成梦
    2020-11-28 01:55

    For Xamarin.iOS:

    UIFont descriptionLabelFont =  UIFont.SystemFontOfSize (11);
    NSString textToMeasure = (NSString)DescriptionLabel.Text;
    
    CGRect labelRect = textToMeasure.GetBoundingRect (
        new CGSize(this.Frame.Width, nfloat.MaxValue), 
        NSStringDrawingOptions.UsesLineFragmentOrigin, 
        new UIStringAttributes () { Font = descriptionLabelFont }, 
        new NSStringDrawingContext ()
    );
    

提交回复
热议问题