我试图让DTCoreText改变JSON中的一些简单HTML。我试图实现简单的" Smoke Text"他们在示例中给出了但我在切换工作时遇到了问题。有没有人在swift 3中使用它。
我不确定此时我是否真正使用了DTCoreText。
func updatethePage(){
if let items = self.swiftyJsonVar2["daily"]["leadmessage"].string {
data = items.data(using: .utf8)
attrString = NSAttributedString(htmlData: data,options:nil, documentAttributes:nil)
print(attrString)
self.leadStory.attributedText = attrString!
}
}
我现在已经开始运行,但它抛出的错误是
Optional(This is the lead message
And naother line
{
CTForegroundColor = "<CGColor 0x600000085c80> [<CGColorSpace 0x6000000348e0> (kCGColorSpaceICCBased; kCGColorSpaceModelMonochrome; Generic Gray Gamma 2.2 Profile; extended range)] ( 0 1 )";
NSFont = "<UICTFont: 0x7f8abb50f270> font-family: \"Times New Roman\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSParagraphStyle = "<CTParagraphStyle: 0x6080000d0840>{base writing direction = -1, alignment = 4, line break mode = 0, default tab interval = 36\nfirst line head indent = 0, head indent = 0, tail indent = 0\nline height multiple = 0, maximum line height = 0, minimum line height = 0\nline spacing adjustment = 0, paragraph spacing = 12, paragraph spacing before = 12\n}";
})
2016-10-06 11:14:56.485 JSONTesting[61040:4582698] -[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x6080000d0840
2016-10-06 11:14:57.251 JSONTesting[61040:4582698] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFType lineBreakMode]: unrecognized selector sent to instance 0x6080000d0840'
*** First throw call stack:
(
0 CoreFoundation 0x000000010876534b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x00000001081c621e objc_exception_throw + 48
2 CoreFoundation 0x00000001087d4f34 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132
3 CoreFoundation 0x00000001086eac15 ___forwarding___ + 1013
4 CoreFoundation 0x00000001086ea798 _CF_forwarding_prep_0 + 120
5 UIFoundation 0x0000000110c028bd __NSStringDrawingEngine + 647
6 UIFoundation 0x0000000110c0b3d4 -[NSAttributedString(NSExtendedStringDrawing) boundingRectWithSize:options:context:] + 797
7 UIKit 0x000000010906eb18 -[UILabel _textRectForBounds:limitedToNumberOfLines:includingShadow:] + 1199
8 UIKit 0x000000010906e42f -[UILabel textRectForBounds:limitedToNumberOfLines:] + 68
9 UIKit 0x0000000109073f53 -[UILabel _intrinsicSizeWithinSize:] + 168
10 UIKit 0x0000000109073916 -[UILabel _ensureBaselineMetricsReturningBounds] + 196
11 UIKit 0x0000000109073a89 -[UILabel _baselineOffsetFromBottom] + 31
12 UIKit 0x00000001090723b4 -[UILabel _baselineOffsetParametersDidChange] + 98
13 UIKit 0x000000010906ffc0 -[UILabel _setAttributedText:andTakeOwnership:] + 229
14 UIKit 0x0000000109070044 -[UILabel setAttributedText:] + 115
15 JSONTesting 0x00000001075de10d _TFC11JSONTesting21importantWPController13updatethePagefT_T_ + 2637
16 JSONTesting 0x00000001075dd334 _TFFC11JSONTesting21importantWPController10updatePageFT_T_U_FGV9Alamofire12DataResponseP__T_ + 868
17 Alamofire 0x0000000107787f59 _TFFFC9Alamofire11DataRequest8responseuRxS_30DataResponseSerializerProtocolrFT5queueGSqCSo13DispatchQueue_18responseSerializerx17completionHandlerFGVS_12DataResponsewx16SerializedObject_T__DS0_U_FT_T_U_FT_T_ + 889
18 Alamofire 0x0000000107787fb7 _TTRGRx9Alamofire30DataResponseSerializerProtocolrXFo___XFdCb___ + 39
19 libdispatch.dylib 0x000000010bf78980 _dispatch_call_block_and_release + 12
20 libdispatch.dylib 0x000000010bfa20cd _dispatch_client_callout + 8
21 libdispatch.dylib 0x000000010bf828d6 _dispatch_main_queue_callback_4CF + 406
22 CoreFoundation 0x00000001087294f9 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
23 CoreFoundation 0x00000001086eef8d __CFRunLoopRun + 2205
24 CoreFoundation 0x00000001086ee494 CFRunLoopRunSpecific + 420
25 GraphicsServices 0x0000000110599a6f GSEventRunModal + 161
26 UIKit 0x0000000108de7f34 UIApplicationMain + 159
27 JSONTesting 0x00000001075d577f main + 111
28 libdyld.dylib 0x000000010bfee68d start + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)
答案 0 :(得分:0)
我不得不把它放到DTCoreTextViewContent中,而不仅仅是普通的lablel。