I used sqlite3 blob type to save NSAttributedString content, query table return NSData type and use below code to convert it to NSAttributedString : let attributeStr = try? NSAttributedString.init(data: data as Data, options: [:], documentAttributes: nil)
textView.attributedText = attributeStrBut the UITextView show this, how to do about this, thanks a lot.sorry, the image not show. just describe :I build a rich text demo with UITextView, get NSAttributedString and save it in db, then query table to get it and show, I edited "Tttt\nRruuoo" on the page, but the UITextView show below: (it's not in console)T{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSFont = " font-family: \".SFUI-Regular\"; font-weight: normal; font-style: normal; font-size: 22.00pt";
NSOriginalFont = " font-family: \"Helvetica\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
}ttt{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSFont = " font-family: \".SFUI-Regular\"; font-weight: normal; font-style: normal; font-size: 22.00pt";
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
}
\
{
NSColor = "UIExtendedGrayColorSpace 0 1";
NSFont = " font-family: \".SFUI-Regular\"; font-weight: normal; font-style: normal; font-size: 14.00pt";
NSParagraphStyle = "Alignment 4, LineSpacing 0, ParagraphSpacing 0, ParagraphSpacingBefore 0, HeadIndent 0, TailIndent 0, FirstLineHeadIndent 0, LineHeight 0/0, LineHeightMultiple 0, LineBreakMode 0, Tabs (\n 28L,\n 56L,\n 84L,\n 112L,\n 140L,\n 168L,\n 196L,\n 224L,\n 252L,\n 280L,\n 308L,\n 336L\n), DefaultTabInterval 0, Blocks (\n), Lists (\n), BaseWritingDirection 0, HyphenationFactor 0, TighteningForTruncation NO, HeaderLevel 0 LineBreakStrategy 0";
}{
NSFont = " font-family: \".SFUI-Regular\"; font-weight: normal; font-style: normal; font-size: 12.00pt";
}
Post
Replies
Boosts
Views
Activity
In my rich text project I use NSTextAttachment to add an image, set attachment.bounds, and it works. Convert NSAttributedString to NSData and store it in sqlite3 and then take it out. Attachment.bounds is lost.How to solve this problem? Thanks a lot.
attachment.image = image
let textPaddingTop:CGFloat = (richTextView.font!.lineHeight - richTextView.font!.pointSize) / 2
attachment.bounds = CGRect.init(x: 0, y: -textPaddingTop, width: image.size.width, height: image.size.height)
In my rich text project I use NSTextAttachment to add an image, but the image is blurred.How to solve this problem? Thanks a lot.
let textAttachment = NSTextAttachment()
textAttachment.image = image
textAttachment.bounds = CGRect(origin: CGPoint.zero, size: image.size)
let textAttachmentString = NSMutableAttributedString(attributedString: NSAttributedString(attachment: textAttachment))
textAttachmentString.addAttribute(NSAttributedString.Key.paragraphStyle, value: paraph, range: NSRange(location: 0, length: textAttachmentString.length))
attributedText.append(textAttachmentString)
}
Test with iphone11(14.6) and watch series3(6.2)
In my project, I use WatchConnectivity between phone and watch to communication,
When watch send message with below code, every time run is OK
wcSession.sendMessage(message as [String : Any], replyHandler: nil)
But when watch send message need reply, it seems error.
wcSession.sendMessage(message) { (reply) in
} errorHandler: { (error) in
}
In Phone with below code to deal with request
func session(_ session: WCSession, didReceiveMessage message: [String : Any]) {
}
func session(_ session: WCSession, didReceiveMessage message: [String : Any], replyHandler: @escaping ([String : Any]) -> Void) {
}
I debug the code, didReceiveMessage replyHandler can be called, and reply data, but watch can not receive the reply. So what’s my problem, Before the mobile and watch update, everything is good, every update will cause problems, how to ensure the stability of the app?Thank you very much.