nsattributedstring

Can I set the `attributedText` property of `UILabel`

你说的曾经没有我的故事 提交于 2019-11-29 19:05:41
Can I set the attributedText property of a UILabel object? I tried the below code: UILabel *label = [[UILabel alloc] init]; label.attributedText = @"asdf"; But it gives this error: Property "attributedText" not found on object of type 'UILabel *' #import <CoreText/CoreText.h> not working Unfortunately, UILabel doesn't support attributed strings. You can use OHAttributedLabel instead. Update: Since iOS6, UILabel does support attributed strings. See UILabel reference or Michael Kessler's answer below for more details. Here is a complete example of how to use an attributed text on a label:

How to Insert NSAttributedString using custom keyboard extension?

↘锁芯ラ 提交于 2019-11-29 18:20:23
问题 I want to write text in some custom fonts using keyboard Extension as these apps (1,2,3,4) are doing. I know how we can insert normal string in document proxy. [self.textDocumentProxy insertText:mystring]; I have tried to insert NSAttributedString using above approach but I can't see any way to insert NSAttributedString to document proxy. Some one can guide what will the best way to get rid of this issue? any suggestion will be appreciated. 回答1: It is not possible to insert attributed strings

How to add Underline/Bold/Italicize Abilities for UITextView Swift [duplicate]

梦想的初衷 提交于 2019-11-29 17:29:50
This question already has an answer here: How to add toggleBoldface option to a UITextView in iOS? 2 answers I have been searching for quite a while for a solution as to how to grant users the ability to underline, italicize and bold text in a UITextView but have not been able to find a solid solution. I have realized that I will need to use an NSAttributedString but am not sure as to how to create the UI and format the string so I am able to save it to a database. If you could point me in a proper direction that would be greatly appreciated. Thanks! The UI is simply an ordinary editable

Localizing attributed UITextView from storyboard

守給你的承諾、 提交于 2019-11-29 17:12:55
问题 I am using the storyboard and have a view where I have subclassed some UITextViews. My problem is that I am using ibtool --generate-strings-file to extract strings from the storyboard for localization and afterwards use ibtool -write on another storyboard file to apply the translated strings. When I use ibtool any UITextViews that have attributed text is ignored by the ibtool --generate-strings-file command and omitted from the resulting strings file. Is it possible to extract attributed text

NSAttributedString performance is worse under iOS 8

旧街凉风 提交于 2019-11-29 15:05:18
问题 Under iOS 8 (and 8.1 beta) the performance of creating an NSAttributedString is much worse than 7 (2-3x). This is especially noticeable if you're using multiple instances on the same view, loading 4 different labels will cause a delay of over a second from when the user taps and the new view appears. Unfortunately you can't even throw this into another thread, since it uses WebKit behind the scenes. I have submitted a bug to Apple, but I need ideas on workarounds or a better implementation

Very slow HTML rendering in NSAttributedString

别说谁变了你拦得住时间么 提交于 2019-11-29 13:58:29
问题 I have UITableView with dynamic sizing cells that displays list of comments in HTML format and I faced with the problem that NSAttributedString renders HTML content extremely slow! Here is snapshot from profiler. I tried to put the NSAttributedString initialization to separate thread, but still slow and user sees empty cells while HTML is being rendered and finally when it finished rendering cell is not layout properly. dispatch_async(GlobalQueue, { let html = NSAttributedString( data: self

Changing Background color on NSAttributedString

家住魔仙堡 提交于 2019-11-29 13:16:55
I just wanted to know how could i change the background color of an NSAttributedString, i can see the background being white all the time, but i want to make it black. Is that possible?? Many thanks! DenVog I think you want NSBackgroundColorAttributeName. Such as: [mutableAttributedString addAttribute:NSBackgroundColorAttributeName value:[UIColor yellowColor] range:selectedRange]; The best plan would really be to draw the string on a view with a black background. For swift 3.x attributedString.addAttribute(NSBackgroundColorAttributeName, value: yourColor, range: NSMakeRange(0, tillLocation))

Change font size without Change UITextView attributedText

你离开我真会死。 提交于 2019-11-29 12:57:28
I try to change a font size in my UITextView and every time I change the attributedText was restore to default. with this I make the middle test bold : str = [[NSMutableAttributedString alloc] initWithAttributedString:string]; [str addAttribute:NSFontAttributeName value:newFont range:NSMakeRange(range.location, range.length)]; before: that was bold font in the middle. after :all the text bold I want that after the size change the bold stay where he be. Edit : I try with this two ways : 1) NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString

Swift 4 Label attributes

半城伤御伤魂 提交于 2019-11-29 12:11:28
问题 I'm moving from swift 3 to swift 4. I have UILabels that I am giving very specific text properties to the label. I'm getting an 'unexpectedly found nil while unwrapping optional value' error when strokeTextAttributes is being initialized. I'm totally lost to be frank. In swift 3 the of strokeTextAttributes was [String : Any] but swift 4 threw errors until I changed it to what it is below. let strokeTextAttributes = [ NSAttributedStringKey.strokeColor.rawValue : UIColor.black,

Applying different attributes for different portions of an NSAttributedstring

北慕城南 提交于 2019-11-29 11:58:15
I know it is possible to apply attributes to an NSAttributedString. But how can we apply different attributes to same attributed string. for the string "This is an attributed text." How can we set a particular attribute(background color or foreground color) to "This is" another attribute(background color or foreground color) to "an attributed text." Is there any way to achieve this....? Also is there any way to set the background color of an NSAttributedString in iOS? Make a mutable copy of the attributed string, and then use either: -setAttributes:range: -addAttributes:range: -addAttribute