nsattributedstring

Parsing text from plist to NSAttributedString

不羁的心 提交于 2019-11-30 18:01:10
问题 I'm loading in text from a plist and displaying it within my app. Ideally I want to be able to specify more complex formatting such as italics, bold and superscript text, and display it in a custom label such as TTTAttributedLabel. Are there any available libraries to parse a string in a given format (preferably a simple text format such as Markdown or Textile) into an NSAttributedString? I am aware that solutions are available for parsing RTF and HTML, but this is overkill for my needs -

How to bold some words in my UITextView using NSMutableAttributedString?

回眸只為那壹抹淺笑 提交于 2019-11-30 17:59:03
I have a UITextView and there are certain words I'm casting with NSString stringWithFormat that I'd like to be bolded. I have looked around Stack Overflow and tried to follow the the postings but I guess I'm not understanding it. Here's what I've been playing around with: NSRange boldedRange = NSMakeRange(0, 4); NSString *boldFontName = [[UIFont fontWithName:@"Helvetica-Bold" size:100]fontName]; NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:self.name]; [attrString beginEditing]; [attrString addAttribute:NSFontAttributeName value:boldFontName range

NSAttributedString: Fit image to container

旧巷老猫 提交于 2019-11-30 14:55:28
I have a NSAttributedString which is made from HTML and it displays some images. The problem is that the images are bigger than the container and I wonder how to fit them in it. Thanks for your help TheFlow_ I finally found how to do that: content.enumerateAttribute(NSAttachmentAttributeName, inRange: NSMakeRange(0, content.length), options: NSAttributedStringEnumerationOptions(0)) { (value, range, stop) -> Void in if let attachement = value as? NSTextAttachment { let image = attachement.imageForBounds(attachement.bounds, textContainer: NSTextContainer(), characterIndex: range.location) let

UITextView attributedText and syntax highlighting

自古美人都是妖i 提交于 2019-11-30 13:05:48
问题 Background So, with iOS 6 an UITextView can take an attributedString, which could be useful for Syntax highlighting. I'm doing some regex patterns in -textView:shouldChangeTextInRange:replacementText: and oftentimes I need to change the color of a word already typed. I see no other options than resetting the attributedText, which takes time. - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { //A context will allow us to not call

How to Insert NSAttributedString using custom keyboard extension?

﹥>﹥吖頭↗ 提交于 2019-11-30 12:57:05
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. It is not possible to insert attributed strings (or otherwise rich content) using the text document proxy. The keyboards you have linked are not

How to allow NSAttributedString text be typed into a UITextView?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-30 12:49:20
问题 I'm trying to allow different styles of text to be typed into a UITextView, a bit like a text editor using simple attributes such as bold or italics. I understand by using the textView's attributedText property I can apply attributes to certain ranges of text. This is nice, but I would like to be able to type attributed text into the textView, which would be toggled by a button (such as the typing of bold text). Here's what I've thought of so far: I've used the -(BOOL)textView:(UITextView *

UILabel: Custom underline color?

眉间皱痕 提交于 2019-11-30 12:42:50
I need the text of a UILabel to be black, but have a light gray underline under the text. Is this possible with NSAttributedString or TTTAttributedLabel ? Or is custom drawing using Core Graphics needed? CLARIFICATION: I need a specific color text on a different color underline. Example: blue text on red underline. Mani You can do with NSAttributedString as below. NSMutableAttributedString* string = [[NSMutableAttributedString alloc]initWithString:@"you string"]; [string addAttribute:NSFontAttributeName value:font range:NSMakeRange(0, string.length)]; [string addAttribute

Displaying NSMutableAttributedString on iOS 8

蓝咒 提交于 2019-11-30 11:48:59
Seems on iOS 8.0 (12A365) NSMutableAttributedString sometimes will not be displayed correctly. The problem obviously occurs when the range of the attribute does not start at the beginning of the text (and if there is no other attribute starting at the beginning of the text). So with 1.) the second word "green" in will not show the green background (bug!) ("cell" is a UITableViewCell with UILabel "label" as a subview): 1.) text = [[NSMutableAttributedString alloc] initWithString:@"Green is green. (-> Bug)"]; [text addAttribute:NSBackgroundColorAttributeName value:[UIColor greenColor] range:

Localizing attributed UITextView from storyboard

烂漫一生 提交于 2019-11-30 11:12:18
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 from a storyboard for localization? Solariane on Xcode 6.1, the best way is to copy the attributed

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

社会主义新天地 提交于 2019-11-30 10:17:06
问题 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 回答1: 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