本文介绍了sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:iOS7替代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我找一个弃用方法的替代方法......
Help me please to find an alternative for deprecated method...
CGSize size = [title sizeWithFont:buttonFont
minFontSize:10
actualFontSize:nil
forWidth:_view.bounds.size.width
lineBreakMode:NSLineBreakByClipping];
可以(boundingRectWithSize:options:attributes:context :)执行此操作吗?像这样...
Can (boundingRectWithSize:options:attributes:context:) do this? Something like this...
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:
[UIFont systemFontOfSize:10], NSFontAttributeName,
nil];
CGSize size = [title boundingRectWithSize:CGSizeMake(_view.bounds.size.width-kBorder*2, _view.bounds.size.height)
options:NSLineBreakByClipping
attributes:attributes
context:nil].size;
我是对的吗?
期待您的建议:)
Am I right?Looking forward your advices :)
推荐答案
查看我之前的回答使用此代码:
Have a look to a previous answer I made here using this code :
- (CGSize)text:(NSString *)text sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size
{
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(7.0))
{
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
nil];
CGRect frame = [text boundingRectWithSize:size
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:attributesDictionary
context:nil];
return frame.size;
}
else
{
return [text sizeWithFont:font constrainedToSize:size];
}
}
这篇关于sizeWithFont:minFontSize:actualFontSize:forWidth:lineBreakMode:iOS7替代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!