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
0
votes
1 answer

NSAttributedText alignment right and left doesn't work for the same object

I have a simple extension for NSAttributedString: convenience init( string: String, strikeThrough: Bool = false, color: UIColor? = nil, font: UIFont? = nil, alignment: NSTextAlignment? = nil ) { var attributes =…
Bartłomiej Semańczyk
  • 59,234
  • 49
  • 233
  • 358
0
votes
1 answer

How to make NSAttributedString link clickable

I have a requirement to display the numbers as clickable link from a string input(contains alphabets and numerals) and on tap of that number it should open an iOS call dialler and should dials that number. Below is what I have tried at the moment,…
johnsena
  • 1
  • 1
  • 2
0
votes
1 answer

UIButton Change Title Color Partially

I want to make button like this picture. In order to implement it like a picture, the color of the button title needs to be partially changed, but I don't know what to do. Here is my code. private let signUpButton = UIButton().then { …
0
votes
0 answers

CIAttributedTextImageGenerator filter - text doesn't fit (NSAttributedString)

I use a Core Image filter CIAttributedTextImageGenerator to generate text as a CIImage. However, sometimes the text just doesn't fit into the resulted CIImage as you can see at the picture: I tried to play with different key-values of…
SmartTree
  • 1,381
  • 3
  • 21
  • 40
0
votes
1 answer

UILabel custom Text

How can I make this text using single UILabel or give any other solution to achieve this design.
0
votes
0 answers

Display text along with border in swift iOS

I will get array of strings those strings need to display with border in swift iOS. Example: let tags = ["Draft", "Sent", "Inbox"] The above list need to convert as a flat string and display in single line as shown in below Expected output with…
iOSDude
  • 274
  • 2
  • 25
0
votes
1 answer

How to adjust vertical center in UILabel?

I made function that set line height and letter spacing in UILabel. extension UILabel { func apply(lineHeight: CGFloat, letterSpacing: CGFloat = 0) { let attributedString = NSMutableAttributedString(string: text ?? " ") let range…
oddK
  • 261
  • 4
  • 14
0
votes
1 answer

Align the image and text in NSAttributed text

I need to align the image and text horizontally and assign that string to a UILabel. Below is my code: let attachment = NSTextAttachment() let text = "Current user." attachment.image = UIImage(named: "icon-horizontal-line") …
0
votes
0 answers

NSAttributedString in SwiftUI

everyone. I am trying to show NSAttributedString in SwiftUI. Since SwiftUI doesn't have any controls capable of it, I am trying to use UIKit controls, wrapped in UIViewRepresentable. I've tried to use UILabel, but it doesn't handle hyperlinks. I've…
DmitryZ
  • 81
  • 1
  • 4
0
votes
3 answers

Text alignment won't work using AttributedString SwiftUI 3

I tried using the new AttributedString in SwiftUI 3 I want to change the alignment, but it won't work. Any things else is working fine, for example I tried change color using attributedString it does work !. But I cannot do anything with…
Basel
  • 550
  • 8
  • 21
0
votes
1 answer

NSTextAttachment.bounds does not work on iOS 15

To add an image attachment to an attributed string I used the following code that works fine before iOS 15: let textAttachment = NSTextAttachment() textAttachment.image = UIImage(named:"imageName")! textAttachment.bounds = CGSize(origin: CGPoint(x:…
Alain Bianchini
  • 3,883
  • 1
  • 7
  • 27
0
votes
2 answers

How to change html list bullet point color for a link item in swift?

I have UITextView and for it I use an HTML string that contains a list of two elements, one of which is a link. I don't want the link text to be the default blue color so I changed it to orange with .linkTextAttributes. But how to set a different…
Heimdallr
  • 189
  • 1
  • 14
0
votes
2 answers

Make Ints within a string bold - swift

Hi I have a string that I'm displaying in a label that shows a time like this "4hours 27mins 45secs" and this can vary based on the time for example "30mins 5secs" I want to style the Ints in the string so they are bold and the characters are light…
Chris
  • 109
  • 1
  • 8
0
votes
0 answers

How can you break an NSMutableAttributedString init?

We are looking to find a case that would cause NSMutableAttributedString to fail when loaded with HTML. Have tried javascript, horrid HTML, etc, and it always just puts an error in the string. We are assuming that there is an error state because…
Rob Bonner
  • 9,276
  • 8
  • 35
  • 55
0
votes
1 answer

How to keep a combination of attributes on a string in swift

I have a string that require to set attributes on it. The attributes(bold, italic, strikethrough, underline) are getting added separately but they are not keeping intact with the string. I want to know how to keep different attributes intact with a…
iosDevSan
  • 65
  • 1
  • 13
1 2 3
99
100