Swift - 计算文本高度

Swift - 计算文本高度,第1张

概述http://www.cnblogs.com/YouXianMing/p/5823893.html //// String+StringHeight.swift// StringHeight//// Created by YouXianMing on 16/8/30.// Copyright © 2016年 YouXianMing. All rights reserved.//

http://www.cnblogs.com/YouXianMing/p/5823893.HTML

////  String+StringHeight.swift//  StringHeight////  Created by YouXianMing on 16/8/30.//  copyright © 2016年 YouXianMing. All rights reserved.//import UIKitextension String {        /**     Get the height with the string.          - parameter attributes: The string attributes.     - parameter fixeDWIDth: The fixed wIDth.          - returns: The height.     */    func heightWithStringAttributes(attributes : [String : AnyObject],fixeDWIDth : CGfloat) -> CGfloat {                guard self.characters.count > 0 && fixeDWIDth > 0 else {                    return 0        }                let size = CGSizeMake(fixeDWIDth,CGfloat.max)        let text = self as Nsstring        let rect = text.boundingRectWithSize(size,options:.UseslineFragmentOrigin,attributes: attributes,context:nil)                return rect.size.height    }        /**     Get the height with Font.          - parameter Font:       The Font.     - parameter fixeDWIDth: The fixed wIDth.          - returns: The height.     */    func heightWithFont(Font : UIFont = UIFont.systemFontOfSize(18),fixeDWIDth : CGfloat) -> CGfloat {                guard self.characters.count > 0 && fixeDWIDth > 0 else {                        return 0        }                let size = CGSizeMake(fixeDWIDth,attributes: [NSFontAttributename : Font],context:nil)                return rect.size.height    }        /**     Get the wIDth with the string.          - parameter attributes: The string attributes.          - returns: The wIDth.     */    func wIDthWithStringAttributes(attributes : [String : AnyObject]) -> CGfloat {                guard self.characters.count > 0 else {                        return 0        }                let size = CGSizeMake(CGfloat.max,0)        let text = self as Nsstring        let rect = text.boundingRectWithSize(size,context:nil)                return rect.size.wIDth    }        /**     Get the wIDth with the string.          - parameter Font: The Font.          - returns: The string's wIDth.     */    func wIDthWithFont(Font : UIFont = UIFont.systemFontOfSize(18)) -> CGfloat {                guard self.characters.count > 0 else {                        return 0        }                let size = CGSizeMake(CGfloat.max,context:nil)                return rect.size.wIDth    }}
总结

以上是内存溢出为你收集整理的Swift - 计算文本高度全部内容,希望文章能够帮你解决Swift - 计算文本高度所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1062168.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存