nsattributedstring

NSAttributedString doesn't work with SCNText

主宰稳场 提交于 2019-12-13 15:39:01
问题 I want to display some text inside a SceneKit scene, where the characters have a different color. The documentation of SCNText states: When you create a text geometry from an attributed string, SceneKit styles the text according to the attributes in the string, and the properties of the SCNText object determine the default style for portions of the string that have no style attributes. I tried this but it doesn't work. SCNText seems to ignore the attributes of my string. I checked if the

Are there approaches for using attributed strings in combination with localization?

血红的双手。 提交于 2019-12-13 12:00:02
问题 Suppose there is this string in English and its a requirement to bold or color etc. to a particular part of a string of text: "word1 word2 WORD3 word4" That can be accomplished by setting the attribute for the appropriate range. The range could be hardcoded to (13,5) but then of course that wouldn't be localizable. So alternatively the range could be dynamically determined by knowing that its the 3rd word that has to have the bold applied to it. But that too isn't localizable. Suppose once

How can I append value if NSAttributedstring contains external link?

时光毁灭记忆、已成空白 提交于 2019-12-13 10:58:54
问题 Hi I'm trying to get html from a website. It has internal and external links. How can I append string if link is external link. By the way internal links has applewebdata:// and I check those ones as internal. But I couldn't understand how can I detect external links. I want just add something like that » . Internal link href: applewebdata:// External link href contains http:// or https:// An example in here 回答1: Here what you could do: Enumerate the link attribute. Check for each value if it

How to pass parameter of AnyObject… to function which parameter need AnyObject

蓝咒 提交于 2019-12-13 10:16:04
问题 I'am using function of NSAttributedString(attributes: [String : AnyObject]?, format: String, arguments: AnyObject...) And I want to customize an general function to call this function above. So I need to send parameter arguments: AnyObject... But this parameter will become [AnyObject] in my customize function. How to fix it? Update : When I use code bellow: typealias Function = ([String : AnyObject]?, String, [AnyObject]) -> NSAttributedString let myAttributedString = unsafeBitCast

How to transfer HTML text into an attributed string without losing line breaks in Swift 3 [duplicate]

泄露秘密 提交于 2019-12-13 07:19:40
问题 This question already has answers here : HTML Format in UITextView (8 answers) Closed 2 years ago . Please do not mark as duplicate. None of the existing questions solves not losing line breaks . Given String: "Regular text becomes <b>bold with </b>\n\n<b><i>An italic</i></b>\n\n<b>Linebreak</b>" I have two options: let attrStr = try! NSAttributedString( data: story.body.data(using: String.Encoding.unicode, allowLossyConversion: true)!, options: [ NSDocumentTypeDocumentAttribute:

How to use NSRange or NSScanner in iOS

流过昼夜 提交于 2019-12-13 07:14:34
问题 I have a string like: 1 this is my first text 2 his is my second 3 this is my third 4 this is my forth etc etc.. Each sentence is between the numeric characters like 1 2 3 4 etc When I tap the first sentence, it needs to dissect it and copy it in clipboard or something. How can we use he NSScanner or NSRange to calculate the string size or identify strings between the numeric characters. self.multiPageView.text =combined; the combined contains the text like above ,,so when i tap the first

color hashtags in NSAttributedString

梦想的初衷 提交于 2019-12-13 06:59:40
问题 I have a label where I have normal text and hashtags. I wanted the hashtags to have a different color, so I did something like this: let text = "#hellothere I am you. #hashtag #hashtag2 @you #hashtag3" let words = text.components(separatedBy: " ") let attribute = NSMutableAttributedString.init(string: text) for word in words { let range = (text as NSString).range(of: word) if word.hasPrefix("#") { attribute.addAttribute(NSForegroundColorAttributeName, value: UIColor.red, range: range) } }

Type 'NSAttributedStringKey' (aka 'NSString') has no member 'foregroundColor'

∥☆過路亽.° 提交于 2019-12-13 04:43:36
问题 Below is line of code for the above mentioned issue. This issue is occurred in Swift 4.1 . let textAttributes = [NSAttributedStringKey.foregroundColor:UIColor.white] navigationController?.navigationBar.titleTextAttributes = textAttributes 回答1: I've fixed this problem by replacing the Key for Attributed String. Here is my updated Code is: let textAttributes = [NSForegroundColorAttributeName : UIColor.white] navigationController?.navigationBar.titleTextAttributes = textAttributes 来源: https:/

UITextView text color doesn't reset after setting attributed text

懵懂的女人 提交于 2019-12-13 04:16:57
问题 I am using UITextView in my app and I'm having a strange behaviour.My UITextView has white color as text color. I am setting some attributed text with blue color in my text view and it works as expected. But as soon as I delete the text, text color turns blue. I have tried setting text color again to white but no luck. See screenshots attached for better understanding of the issue. UPDATE 1. code to turn particular text to blue -(NSMutableAttributedString*)decorateTagsWithString:(NSString *

iOS swift: textView with links to another view

梦想的初衷 提交于 2019-12-13 03:58:13
问题 I'm trying to make a TextView with some test like this one: Cras et enim ipsum. Nullam rhoncus euismod nisi at convallis. Etiam accumsan libero odio, eget malesuada ligula bibendum venenatis. where the links bring you to an other ViewController... I think I should use attributed text to accomplish this, but I really can't figure how... The other solution would be to use buttons surrounded by labels, but it is not elegant... Helps? 回答1: Use UITextView delegate method textView(_