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
37
votes
3 answers

Wrapping Text in a UITextView Around a UIImage WITHOUT CoreText

Is there a way to wrap text from a UITextView around a UIImage without using CoreText? I have been playing around with attributed strings without much luck, and CoreText just seems extremely complicated so I would rather stay out of it.
harryisaac
  • 1,121
  • 1
  • 10
  • 18
35
votes
8 answers

How to set color of templated image in NSTextAttachment

How can I set the color of a templated image that is an attachment on an attributed string? Background: I've got a UILabel and I'm setting its attributedText to an NSAttributedString. The NSAttributedString includes an NSTextAttachment with a small…
Ghazgkull
  • 970
  • 1
  • 6
  • 17
34
votes
1 answer

UILabel and NSLinkAttributeName: Link is not clickable

I want to use attributed strings with NSLinkAttributeName to create clickable links inside a UILabel instance within my iOS 7 project, which is now finally possible without using external libraries. NSURL *url = [NSURL…
Habizzle
  • 2,971
  • 3
  • 20
  • 23
34
votes
1 answer

How can I set the color and alignment of attributed text in a UITextView in iOS 7?

The formatting of my textViews worked fine in iOS 6, but no longer in iOS 7. I understand with Text Kit much of the under the hood stuff has changed. It's become really quite confusing, and I'm hoping someone can help straighten it out a bit by…
Joe
  • 854
  • 3
  • 11
  • 21
33
votes
7 answers

NSAttributedString inserting a bullet point?

So I have an NSAttributedString I want to insert a bullet point at the beginning of a portion of text. How can I do this? How do I create a CTPAragraphStyle that creates this bullet point when I display the text? Edit: Should be available on iOS
aryaxt
  • 76,198
  • 92
  • 293
  • 442
33
votes
3 answers

NSAttributedString tail truncation in UILabel

I'm using ContextLabel to parse @ , # and URL's. This is the best solution i found, cause it sizes correctly and dont affect performance. It firstly parses string at input and than converts it to NSAttributedString and after this assigns it to…
Nikita Semenov
  • 2,111
  • 4
  • 18
  • 31
33
votes
6 answers

how to resize an image or done as a NSAttributedString NSTextAttachment (or set its initital size)

I have a NSAttributedString to which I am adding a NSTextAttachment. The image is 50w by 50h but I'd like it to scale down to reflect the line height of the attributed string. I thought this would be done automatically but I guess not. I have looked…
timpone
  • 19,235
  • 36
  • 121
  • 211
33
votes
4 answers

Looping Through NSAttributedString Attributes to Increase Font SIze

All I need is to loop through all attributes of NSAttributedString and increase their font size. So far I got to the point where I successfully loop through and manipulate attributes but I cannot save back to NSAttributedString. The line I commented…
Vad
  • 3,658
  • 8
  • 46
  • 81
33
votes
9 answers

Is it possible to change color of single word in UITextView and UITextField

Is it possible to change color of single word in UITextView and UITextField ? If i have typed a word with a symbol infront (eg: @word) , can it's color be changed ?
Nithin M Keloth
  • 1,595
  • 1
  • 20
  • 37
30
votes
4 answers

NSUnderlineStyleAttributeName Underline spacing

I want the underline to be below the text like any other normal underlining mechanism. However, with NSAttributed string it leaves holes with "g's" and "y's" example: How it should look: How can I increase the spacing between the underline and…
MobileMon
  • 8,341
  • 5
  • 56
  • 75
30
votes
5 answers

UIPickerView won't allow changing font name and size via delegate's `attributedTitleForRow...`

I use the following func to change the font color and font size, the color works but the font name and font size refuse to work. func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) ->…
jdleung
  • 1,088
  • 2
  • 10
  • 26
30
votes
2 answers

What is the equivalent of NSLineBreakMode in iOS 7 attributed strings drawing methods?

There was a method - (CGSize)drawInRect:(CGRect)rect withFont:(UIFont *)font lineBreakMode:(NSLineBreakMode)lineBreakMode alignment:(NSTextAlignment)alignment; which I must replace now for iOS 7. I get as far as NSDictionary *attributes =…
openfrog
  • 40,201
  • 65
  • 225
  • 373
27
votes
2 answers

How do i convert NSAttributedString into HTML string?

As the title tells,now i can simple convert HTML into NSAttributedString with initWithHTML:documentAttributes: , but what i want to do here is reverse. Is there any 3rd party library to achieve this? @implementation…
NeXT5tep
  • 861
  • 1
  • 11
  • 23
27
votes
2 answers

Appending NSAttributedString with line break returns attributed string with wrong format

I'm using NSMutableAttributedString and NSAttributedString to display a label text in two different font sizes. My approach is: NSMutableAttributedString *muAtrStr = [[NSMutableAttributedString alloc]initWithString:@"2"]; NSAttributedString *atrStr…
user3404693
  • 555
  • 1
  • 8
  • 19
27
votes
7 answers

iOS 7 BUG - NSAttributedString does not appear

Last week I asked a question about a Simulator bug with NSAttributedString not displaying: iOS 7 Simulator Bug - NSAttributedString does not appear Unfortunately it now appears this is not a simulator bug but an iOS 7 bug. I have now reproduced this…
RohinNZ
  • 3,338
  • 5
  • 24
  • 34