Weird behaviour of boundingRectWithSize:options:attributes:context:

本小妞迷上赌 提交于 2020-01-02 19:12:06

问题


I am experiencing a strange issue related to boundingRectWithSize:options:attributes:context:

This is the code

        NSString *text = @"These long strings work";
        CGSize maxSize = CGSizeMake(176.0f, MAXFLOAT);
        CGRect rect = [text boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:16.0]} context:nil];
        CGSize size = rect.size;

I have an xcode iOS project which uses this code. When I run the project, the size is (width=149.8125, height=18.1796875)

I created a new single page application project in xcode and tested the same code there. size is (width=172.944031, height=19.0880013) (which matches the frame size of UILabel created with same title and same font in interface builder)

Apple docs for boundingRectWithSize:options:attributes:context:

Calculates and returns the bounding rect for the receiver drawn using the given options and display characteristics

Is this behaviour due to some display characteristics that might be different across projects?

来源:https://stackoverflow.com/questions/25562838/weird-behaviour-of-boundingrectwithsizeoptionsattributescontext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!