boundingRectWithSize:options:attributes:context用法

导入:

MBProgressHUD出警告

如:

- (CGSize)sizeWithFont:(UIFont*)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakModeNS_DEPRECATED_IOS(2_0,7_0,"Use -boundingRectWithSize:options:attributes:context:");

提示用:boundingRectWithSize:options:attributes:context:这个方法

CGFloat remainingHeight = bounds.size.height - totalSize.height - kPadding - 4 * margin;

CGSize maxSize = CGSizeMake(maxWidth, remainingHeight);

/*

CGSize detailsLabelSize = [detailsLabel.text sizeWithFont:detailsLabel.font

constrainedToSize:maxSize lineBreakMode:detailsLabel.lineBreakMode];*/

NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:20]};

CGSize detailsLabelSize = [detailsLabel.text boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine attributes:attributes context:nil].size;

以及

- (CGSize)sizeWithFont:(UIFont *)font NS_DEPRECATED_IOS(2_0, 7_0, "Use -sizeWithAttributes:") __TVOS_PROHIBITED;

如下写法

CGSize labelSize = [label.text sizeWithAttributes:@{NSFontAttributeName:label.font}];

几个参数:

size:范围自己决定

options :这是一个枚举类型

typedefNS_ENUM(NSInteger, NSStringDrawingOptions) {

NSStringDrawingTruncatesLastVisibleLine = 1 << 5,

NSStringDrawingUsesLineFragmentOrigin = 1 <<0,

NSStringDrawingUsesFontLeading = 1 <<1,

NSStringDrawingUsesDeviceMetrics = 1 <<3,

} NS_ENUM_AVAILABLE_IOS(6_0);

自己选一个适合的

attributes:字典

NSDictionary *attributes = @{NSFontAttributeName:[UIFontsystemFontOfSize:20]};

context:文本绘制的规范定义,一半为nil就可以

其他的大家触类旁通把

时间: 2024-08-29 14:49:10

boundingRectWithSize:options:attributes:context用法的相关文章

-boundingRectWithSize:options:attributes:context:用法

导入第三方一些类库后,出现一些警告就是某些方法被弃用了: 如: - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size lineBreakMode:(NSLineBreakMode)lineBreakModeNS_DEPRECATED_IOS(2_0,7_0, "Use -boundingRectWithSize:options:attributes:context:"); 提示用:boundingRec

&#39;sizeWithFont:constrainedToSize:&#39; is deprecated: first deprecated in iOS 7.0 - Use -boundingRectWithSize:options:attributes:context:

解决方法: NSString *myText = @"xxxxx"; 将 CGSize mySize =[myText sizeWithFont:myFont constrainedToSize:CGSizeMake(200,100)]; 改写成: CGSize mySize = [myText boundingRectWithSize:CGSizeMake(200,100) options:NSStringDrawingUsesLineFragmentOrigin attribute

boundingRectWithSize:options:attributes:context:

boundingRectWithSize:options:attributes:context:计算文本尺寸 之前使用NSString类的sizeWithFont:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个boudingRectWithSize:options:attributes:context方法来代替: 关于该类,有一篇关于NSAttributedString UIKit Additions Reference翻译的文章:http://blog.csdn.

通过boundingRectWithSize:options:attributes:context:计算文本尺寸

转:http://blog.csdn.net/jymn_chen/article/details/10949279 之前用Text Kit写Reader的时候,在分页时要计算一段文本的尺寸大小,之前使用了NSString类的sizeWithFont:constrainedToSize:lineBreakMode:方法,但是该方法已经被iOS7 Deprecated了,而iOS7新出了一个boudingRectWithSize:options:attributes:context方法来代替: 很碍

iOS7 中 boundingRectWithSize:options:attributes:context:计算文本尺寸的使用

CGSize constraintSize; constraintSize.width = MAXFLOAT; constraintSize.height = 32; //CGSize sizeFrame =[content.text sizeWithFont:WBLText16Font constrainedToSize:constraintSize lineBreakMode:NSLineBreakByWordWrapping]; //旧的 //新的 NSDictionary *attrib

Android -- Options Menu,Context Menu,Popup Menu

Options Menu                                                                           创建选项菜单的步骤: 1.覆盖Activity 的onCreateOptionMenu(Menu menu)方法,当菜单第一次被打开时调用 2.调用Menu 的add( )方法添加菜单项(MenuItem),同时可以调用MenuItem 的setIcon( )方法来为菜单项设置图标 3.当菜单项(MenuItem)被选择时,

文本属性Attributes的用法

文本属性Attributes 1.NSKernAttributeName: @10 调整字句 kerning 字句调整 2.NSFontAttributeName : [UIFont systemFontOfSize:_fontSize] 设置字体 3.NSForegroundColorAttributeName :[UIColor redColor] 设置文字颜色 4.NSParagraphStyleAttributeName : paragraph 设置段落样式 5.NSMutablePar

C#中的Attributes的用法

今天研究了一下C#中的Attributes的用法,感觉很有用,现总结以下: 在前台用JS写的脚本方法,除了可以直接用在前台控件的属性中,还可以在后台运用. 即在后台页面加载时,调用JS方法.语法格式有两种,如下: 第一种写法:控件ID名.Attributes.Add(“事件名称”,“JS方法”); 如:一个按钮控件Button1.Attributes.Add(“onclick”,“return confirm('确认?')”); 另一写法:控件ID名.Attributes["事件名称"

计算文本的高度BoundingRectWithSize:options:context

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options context:(NSStringDrawingContext *)context 解释一下三个参数 1)  size 用于限制尺寸,计算机绘制时会在这个size的限制范围内 2)options 文本绘制时的附加选项 例: NSStringDrawingUsesFontLeading使用字体来限制高度 3)context 上下文.