Questions tagged [nsattributedstring]

NSAttributedString objects manage character strings and associated sets of attributes (for example, font and kerning) that apply to individual characters or ranges of characters in the string. An association of characters and their attributes is called an attributed string.

NSAttributedString and NSMutableAttributedString declare the programmatic interface for read-only attributed strings and modifiable attributed strings, respectively. The Foundation framework defines only the basic functionality for attributed strings; in Mac OS X, additional methods supporting RTF, graphics attributes, and drawing attributed strings are described in NSAttributedString Additions, found in the Application Kit. The Application Kit also uses a subclass of NSMutableAttributedString, called NSTextStorage, to provide the storage for the Application Kit’s extended text-handling system.

In Mac OS X, the Application Kit also uses NSParagraphStyle and its subclass NSMutableParagraphStyle to encapsulate the paragraph or ruler attributes used by the NSAttributedString classes.

An attributed string identifies attributes by name, storing a value under the name in an NSDictionary object. In Mac OS X, standard attribute keys are described in the “Constants” section of NSAttributedString Application Kit Additions Reference. You can also assign any attribute name/value pair you wish to a range of characters—it is up to your application to interpret custom attributes (see Attributed String Programming Guide). If you are using attributed strings with the Core Text framework, you can also use the attribute keys defined by that framework.

Note that the default font for NSAttributedString objects is Helvetica 12-point, which differs from the Mac OS X system font Lucida Grande, so you may wish to create the string with non-default attributes suitable for your application using, for example, initWithString:attributes:.

Resource

2249 questions
9
votes
1 answer

Link in UITextView not working in Swift 4

I'm using iOS 11 and Swift 4. I am trying to programmatically generate a link inside a UITextView. All the attributes work (i.e. color, size, range etc.) - but unfortunately, the link does not work. Can anybody tell me why? Here is my…
iKK
  • 6,394
  • 10
  • 58
  • 131
9
votes
2 answers

Advance search implementation in iphone?

I want to implement advance search functionality so that if a particular text is typed in search bar, the list of contents in UITableview should be filtered based on the search and then the search text occurances should be highlighted? Please give…
None
9
votes
1 answer

How to stop enumerating attributes of a NSAttributedString?

In the documentation of the enumerateAttribute method it is said, regarding the stop argument of the block, that: The block can set the value to true to stop further processing of the set. However, inside the block the stop argument is a let and I…
AppsDev
  • 12,319
  • 23
  • 93
  • 186
9
votes
1 answer

Maintain custom attributes when replacing attributed text on UITextView

I have a editable UITextView that gets loaded with an attributed String. This attributed String is loaded with custom attributes set by the app. For this reason I always add these custom attributes to the typingAttributes of the textView. Whenever…
Afonso
  • 417
  • 1
  • 5
  • 16
9
votes
2 answers

NSAttributedString with tabs

How do you create a UILabel with this kind of text format? Would you use NSAttributedString?
Hebbian
  • 344
  • 5
  • 16
9
votes
1 answer

Find CGPoint Location of substring in TextView

I'm looking to create a SpriteKit Node positioned at the location of a substring inside a UITextView. How would I retrieve the CGPoint location so I can position the SKNode there? let textFont = [NSFontAttributeName: UIFont(name: "GillSansMT",…
Chris
  • 471
  • 1
  • 8
  • 23
9
votes
3 answers

HTML to NSAttributedString and NSAttributedString to HTML

I want to convert a html string to NSAttributedString and then work on the string like (change colors, fontsizes, fontfamily, background- , foreground-color...) and then convert the string back to plain html from the NSAttributedString. Converting…
9
votes
2 answers

How could you make a uilabel wrap around an image (like shown)

How could you achieve this effect: Maybe some sort of NSAtributedString? I have thought of hacky ways to just add spaces, but it needs to do it dynamically based on the width of the image. Any ideas? NOTE happily you can do this very easily with…
evenodd
  • 2,026
  • 4
  • 26
  • 38
9
votes
1 answer

Position of NSTextAttachment inside UILabel?

I have a UILabel displaying an NSAttributedString. The string contains text and a UIImage as a NSTextAttachment. When rendered, is there a way to get the position of the NSTextAttachment in the UILabel? Edit Here is the end result I am trying to…
rdougan
  • 7,217
  • 2
  • 34
  • 63
9
votes
2 answers

Add attachment image to attributed string in iOS 6

I have spent 3 hours on this but just can't solve it, anybody knows why? please help me! The code below added an image as an attachment to an attributed string, UIImage *img = [UIImage imageNamed:imgName]; NSTextAttachment *textAttachment =…
Fuli
  • 273
  • 2
  • 4
  • 11
9
votes
1 answer

Scrolling Performance issue with UItextView with large NSAttributedString

I am working on text editor for an app. I am using UITextView See the sample code to load text view. // Read text from file (around 300k - 400k words) NSError *error = nil; NSString *contentOfFile = [[NSString alloc]…
9
votes
3 answers

UITextView NSAttributedString Size

I'm working on an app which uses a UITextView. The UITextView should grow or shrink to fit its text, both vertically and horizontally. To do this, I'm overriding sizeToFit in a subclass, and I set the bounds like so: - (void)sizeToFit { [self…
Tom Irving
  • 10,041
  • 6
  • 47
  • 63
9
votes
2 answers

Is it possible to adjust the baseline in NSAttributedString?

I'd like to slightly modify the y position of a character in an NSAttributedString. I know I can subscript (or superscript) using the attribute dictionary: @{(id)kCTSuperscriptAttributeName: @(-1)} Unfortunately the shift caused by this is too…
Ortwin Gentz
  • 52,648
  • 24
  • 135
  • 213
9
votes
4 answers

Is it possible to set multiple font attributes using an NSAttributedString

I am trying to decrease the size of a portion of my string and am using the below code. My output is not correct. I am only seeing my first font attribute being used for the entire string, not the specified range. NSMutableAttributedString…
propstm
  • 3,461
  • 5
  • 28
  • 41
9
votes
1 answer

using nsattributedstring and nslocalizedstring

My old code uses NSLocalizedString to display the following where outputText was an NSMutableString that contained many such lines in a single output session: [outputText appendFormat: NSLocalizedString(@"\n\n%@ and %@ are identical. No comparison…
Mickey
  • 95
  • 1
  • 6