美文网首页
字符串的size

字符串的size

作者: MeteorCode | 来源:发表于2017-02-20 18:22 被阅读14次

CGSize lableSize = [str boundingRectWithSize: strSize options: NSStringDrawingUsesLineFragmentOrigin attributes: @{ NSForegroundColorAttributeName : [UIColor redColor] } context: nil ].size;

解释:

1 - boundingRectWithSize属性:限定文本在固定范围内进行显示

2 - options属性:

1 )  NSStringDrawingTruncatesLastVisibleLine:如果文本内容超出指定的矩形限制,文本将被截去并在最后一个字符后加上省略号。如果没有指定 NSStringDrawingUsesLineFragmentOrigin选项,则该选项被忽略。

2 ) NSStringDrawingUsesLineFragmentOrigin: 绘制文本时使用 line fragement origin 而不是 baseline origin。

3 ) NSStringDrawingUsesFontLeading: 计算行高时使用行距 , 字体大小+行间距=行距

4  ) NSStringDrawingUsesDeviceMetrics: 计算布局时使用图元字形(而不是印刷字体)。

3 - attributes属性:字体属性

NSForegroundColorAttributeName  -- 颜色

NSFontAttributeName -- 字体

NSParagraphStyleAttributeName -- 设置段落样式

NSBackgroundColorAttributeName -- 设置背景颜色

NSLigatureAttributeName - 连体

NSKernAttributeName  -- 调整字句 kerning 字句调整

NSStrikethroughStyleAttributeName -- 添加删除线

NSStrikethroughColorAttributeName -- 删除线颜色

NSUnderlineStyleAttributeName -- 添加下划线

NSUnderlineColorAttributeName -- 下划线颜色

NSStrokeColorAttributeName  -- 设置文字描边颜色

NSStrokeWidthAttributeName -- 设置描边宽度,这样就能使文字空心.

NSShadowAttributeName -- 设置阴影,单独设置不好使,必须和其他属性搭配才好使。和这三个任一个都好使,NSVerticalGlyphFormAttributeName,NSObliquenessAttributeName,NSExpansionAttributeName

NSTextEffectAttributeName --  特殊效果

NSAttachmentAttributeName

NSLinkAttributeName -- 网址

NSBaselineOffsetAttributeName -- 基线偏移量

NSWritingDirectionAttributeName -- 书写方向

NSObliquenessAttributeName -- 设置字体倾斜。Skew 斜

NSVerticalGlyphFormAttributeName -- 该属性所对应的值是一个 NSNumber 对象(整数)。0 表示横排文本。1 表示竖排文本。在 iOS 中,总是使用横排文本,0 以外的值都未定义。

NSExpansionAttributeName -- 设置文本扁平化

4 - context属性:文本上下文。可调整字间距以及缩放等。最终,该对象包含的信息将用于文本绘制。该参数可为nil

参考:

http://www.tuicool.com/articles/zquENb

http://www.jianshu.com/p/9ffcdc0003e0

相关文章

网友评论

      本文标题:字符串的size

      本文链接:https://www.haomeiwen.com/subject/bmyewttx.html