我如何做以下 – 在swift中传递两个NSStringDrawing选项作为函数参数:
CGRect boundingRect = [string boundingRectWithSize:CGSizeMake(280.0,NSIntegerMax) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:options context:nil];
编辑:这是如何使用Swift 2.0中的选项枚举:
原文链接:https://www.f2er.com/swift/321067.htmllet options: NSStringDrawingOptions = [.UsesLineFragmentOrigin,.UsesFontLeading]
编辑:问题has been resolved in iOS 8.3 SDK Beta 1 (12F5027d):
Modified
NSStringDrawingOptions
[struct]
- From:
enum NSStringDrawingOptions : Int
- To:
struct NSStringDrawingOptions : RawOptionSetType
你现在可以写:
let options : NSStringDrawingOptions = .UsesLineFragmentOrigin | .UsesFontLeading
经过一番研究和@Anton Tcholakov的“评论”:
>如果您定位的是OS X 10.10,这是一个简单的方法:
let size = CGSize(width: 280,height: Int.max) let options : NSStringDrawingOptions = .UsesLineFragmentOrigin | .UsesFontLeading let boundingRect = string.bridgeToObjectiveC().boundingRectWithSize(size,options: options,attributes: attributes,context: nil)
>然而,在iOS 8 SDK(在当前种子)中,有一个错误,其中NSStringDrawingOptions被移植到Swift作为枚举:Int,而不是struct:RawOptionSet。你应该向Apple发送一个bug报告,描述这个严重的问题。