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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
13 views

How to get mouse tracking and click events on an NSTextAttachmentCell?

I have an non-editable NSTextField which I'm filling with NSTextAttachments, each of which is styled like a token. I now want to be able to mouseover a token and get a cancel button in the token, ...
  • 3,655
0 votes
1 answer
25 views

TextView Failing To Remove Tab Stops (MacOS)

I'm trying to change the width of tab characters in a text view like so: let paragraph = NSParagraphStyle.default.mutableCopy() as! NSMutableParagraphStyle paragraph.tabStops.removeAll() // Set the ...
-2 votes
0 answers
14 views

Swift Changing Alpha of an NSAttibutedString [duplicate]

can someone explain what an NSAttributedString? Why would we use this instead of just string? Also Is there a way to change the Alpha of an NSAttributedString?
  • 17
0 votes
2 answers
54 views

Swift/UIKit Push to new View Controller when clicked inside a UILabel

I have a signup page in my app and I want users to be able to view terms of service (TermsOfServiceViewController) and privacy policy (PrivacyPolicyViewController) when user pressed text inside my ...
0 votes
1 answer
46 views

How to resize an in-line image within Text in SwiftUI?

I want to resize an in-line image that I added to a multi-line Text. How do I resize Image(systemName: "chevron.right") to be smaller? So far I tried adding .resizable(capInsets:) to the ...
2 votes
2 answers
154 views

Encode AttributedString with custom attributes to JSON

Swift 5.5 introduced AttributedString conforming to Codable however this is not working for me as I'd expect. Take the following example: Here I define a custom attribute TextCase public enum TextCase:...
  • 1,317
0 votes
1 answer
39 views

Swift: joined() for Array of NSAttributedString?

In Swift, you can join an Array of String like so: let a = ["fee", "fi", "fo", "fum"] print(a.joined(separator: " ")) // -> "fee fi fo fum&...
  • 11.6k
1 vote
1 answer
47 views

How do you add an image attachment to an AttributedString?

I'm working to replace NSAttributedString with AttributedString but have been unsuccessful in getting attachments to work. The image doesn't appear in the string despite the fact I applied the ...
  • 51.4k
0 votes
0 answers
18 views

Add NSMutableAttributedString that results to HTML h1 element if converted

I am using the following code to create a NSAttributedString. let titleAttributes: [NSAttributedString.Key: Any] = [ .font: UIFont.systemFont(ofSize: 24), .foregroundColor: UIColor.black, ....
  • 11.4k
-2 votes
1 answer
64 views

How to find urls in NSAttributedString? [duplicate]

I have simple attributed string: let string = NSAttributedString(string: "hello https://www.stackoverflow.com") When I display that string I would like to see: hello URL where URL is ...
0 votes
1 answer
55 views

Remove HTML elements from NSAttributedString

let string = "To find out more, click <a href=\"example.com\"><span>here</span></a> to go to our help page" let attributedString = NSAttributedString(string:...
0 votes
0 answers
48 views

UIbutton inside UILabel text

I am trying to design a UIlabel with clickable UIButton's inside like in the image below. The idea here is that I am getting some text which contains some markers and when that marker appears I have ...
  • 4,799
0 votes
1 answer
18 views

Get NSAttributedString from UITextField within NSRange

Let's assume I have this code: let string = "This is a <b>bold</b> text" let data = Data(string.utf8) let attributedText = try! NSAttributedString(data: data, options: [....
0 votes
0 answers
22 views

TextAttribute not getting applied

I have 3 function where Im drawing text on Image. The text includes attribute paragraphStyle = .right, but the text always getting aligned to left. These are my function : Function Name drawText() : ...
0 votes
1 answer
44 views

[__NSCFType set]: unrecognized selector with NSAttributedString:draw() gets called, based on width of position

If the code below is run it causes an exception 'NSInvalidArgumentException', reason: '-[__NSCFType set]: unrecognized selector sent to instance 0x283130be0' However, the exception can be removed by ...
  • 37.6k
0 votes
2 answers
104 views

How do I mirror an NSAttributedString with an icon and text in right-to-left mode

I have a UIButton that holds an NSAttributedString that contains an icon (which is an NSAttributedString itself) followed by a text. It looks something like this: I want to make it look like this ...
9 votes
0 answers
115 views

HTML string to NSAttributed string, Bullet point with sub bullet point issue Swift

I am converting an HTML string to an NSAttributedstring to set in TextView, while in text, there are bullet points with sub-bullet points. Bullet points are coming correctly but sub-bullet point ...
0 votes
0 answers
29 views

Swift AttributedString font size resized by .76666 (recurring) when saved to RTF via NSAttributedString

iOS 16.2. XCode 14.2. Block below is a simple AttributedString creation and save. The two AttributedExtensions functions for custom append() and Bold(). The text is saved as an RTF file using ...
  • 29
1 vote
0 answers
21 views

How to draw NSAttributedString with .background attributes and insets?

I need to draw in CALayer subclass NSAttributedString with background for every line of text and insets(horizontal and vertical). How to do that? I am trying this code. But, I can't set insets text ...
0 votes
0 answers
17 views

Swift Xcode warning / Expression implicitly coerced from '[NSAttributedString.Key : UIFont?]' to '[NSAttributedString.Key : Any]' [duplicate]

I'm getting this warning which is showing fairly randomly in XCode14.1, mainly at build but then disappears. My code is : let attributes = [NSAttributedString.Key.font:UIFont(name: "...
  • 194
0 votes
0 answers
21 views

LineHeight attribute on NSAttributedString is working backwards?

I was messing around with line heights but I can't understand what's going on. How is lineHeight = 8: and lineHeight = 28: func attributedString(lineHeight: CGFloat) -> NSAttributedString { ...
  • 2,122
0 votes
1 answer
55 views

Swift String - How to replace a word with an image in a localized string?

in this app we have a localized string (more than 10 languages) and in this string there is a word "%1$s" which should be replaced by an image (a logo). Having so many languages means that ...
0 votes
0 answers
107 views

Why does all formatting disappear from an NSTextView when using NSViewRepresentable and SwiftUI?

I am making a small program using SwiftUI that allows users to create rich text "notes" in an NSTextView. I have enabled all of the formatting features from NSTextView, including the ability ...
0 votes
1 answer
103 views

Swift NSTextAttachment with Tap recognition inside TextView

Problem: How can I recognize tap recognition on a NSTextAttachment? I have a image attachment that is appended to the end of an AttributedString on a textView inside a tableView cell. How can I add a ...
1 vote
2 answers
110 views

How to copy all attributes from one AttributedString to another without converting to NSAttributedString?

I have an AttributedString with a set of attributes I don't know until runtime. Now I want to append / prepend another string. How do I get the appended string to have the same attributes as the ...
  • 13
0 votes
0 answers
77 views

Rendering text in italics using core text in iOS

I want to render text in italics using core text. In UILabel, I was able to apply italics style(basically slanting the text) for a regular font by adding obliqueness attribute to the ...
  • 19
1 vote
0 answers
52 views

CIAttributedTextImageGenerator - multiline text image generation problem in iOS 16

I am usinig CIAttributedTextImageGenerator to generate text into CIImage in my app. let attributes: [NSAttributedString.Key: Any] = [ .font: font, .foregroundColor: textColor, ....
  • 1,371
0 votes
0 answers
50 views

Text Wrapping not happening as it should in NSTextField Attributed String

I am having an issue with text not wrapping correctly if there is a single quote, or macOS ASCII Extended Character #213 (shift+opt.+]) in a string. Apple does not escape the media item title string ...
0 votes
1 answer
53 views

Hyperlink is not getting highlighted when translating from English to French/German in swift

I have a UILabel with hyperlink text. Here is the code: let termsText = NSLocalizedString("To continue using this feature, please accept the Terms & Conditions", bundle: Bundle.terms, ...
  • 33
0 votes
0 answers
74 views

UITextView Scrolling Up And Down Upon Typing New Line or Character

I have a UITextView. It reads its text string and parses the markdown and displays it on screen using NSAttributedString from AttributedString. The Problem When the text is short, it's all good. But ...
  • 111
0 votes
0 answers
22 views

How can I get the CIAttributedTextGenerator filter to break onto multiple lines?

I'm working on an app that overlays text onto an image. We want to be able to constrain the width of the text and have it break onto multiple lines, much in the same way that UILabel does when we set ...
0 votes
0 answers
49 views

Appearance contradicts Code, In Simple AttributedString NSParagraphStyle Displayed In UITextView

I'm trying to parse a markdown string manually and create an attributedString for UITextView When I try to format code blocks, I found some weird bug that I can't solve. I've reduced the problem to ...
  • 111
1 vote
2 answers
127 views

Swift attribute for new line in NSAttributedString

I have a UITextView with a lightGray text. I would like the color to always be set to black with each new line so that I can be sure that the new line is always black regardless of the color of the ...
0 votes
1 answer
85 views

swift get range of attribute by index in NSAttributedString

I have a NSAttributedString with 2 attributes From 0 to 5 {0,5} -> attribute1 from 6 to 10 {6,10} -> attribute2 I use let attributes = textView.textStorage.attributes(at: 7, ...
2 votes
1 answer
165 views

NSAttributedString with image attachments overlapping text in iOS 16

I have stumbled upon an issue with NSAttributedString and NSTextAttachment in UITextView on iOS16. It works in iOS 15 and appends the images after the text, but in iOS 16 the images are placed on top ...
  • 484
0 votes
0 answers
147 views

Attributed String not showing with its attributes

I have a label with a text similar to this "My <link href='..here goes an url'>first</link>and <link href='...secondUrl'>second</link> I've done a function that receives ...
0 votes
1 answer
238 views

Vertical images being rotated horizontally when adding and saving to NSAttributedString in IOS?

I have a problem that I have been trying to solve for days. When resizing an image that's in a NSAttributedString using NSTextAttachment the vertical images are saved horizontally. The resizing ...
  • 117
0 votes
1 answer
46 views

SCNText ignores NSAttributedString attributes

Although the docs claim that SceneKit's SCNText works with NSAttributedString, the following NSAttributedString attributes seem to be ignored completely (and perhaps others, too): shadow strokeColor ...
  • 1,270
0 votes
1 answer
28 views

How to handle hex values in NSAttributedString color

I am trying to use NSAttributedString to get the color attribute from a sample HTML string. Here is how I am trying to create it: func toHTMLAttributedString() -> NSAttributedString? { if let ...
1 vote
1 answer
43 views

Highlight specific string value dynamically

Highlight words in between response dynamic data names "Work for Joy Bag is Started" "Work for Jack & Jill is Ended" "Work for Uncle Sam is Started" Need to ...
  • 4,237
0 votes
0 answers
30 views

How can I present a long-press menu for a link in a UITextView that is a custom URL scheme of mine?

In my app I have a UITextView where I parse the text, detect references to content in my app, and add hyperlinks to that content via NSAttributedString / NSLinkAttributeName. Right now I have it set ...
  • 10.4k
0 votes
2 answers
210 views

Dynamic Text Sizing in NSAttributedString

I'm trying to support Large Font Accessibility in the app. There are places where we are using NSAttributedString to set the attributedText of a UILabel. On UILabel, we've set ...
  • 23.4k
0 votes
1 answer
32 views

Conflicting attributes on NSMutableAttributedString: .foregroundColor vs .strokeWidth

I have created a var with default text attributes for an NSMutableAttributedString: static var textFieldDefaultTextAttributes: [NSAttributedString.Key: Any] = [ .font: UIFont(name: "Impact"...
  • 135
-1 votes
1 answer
283 views

iOS 14+ SwiftUI Rendering TextView DataDetector without WebKit

When using SwiftUI with iOS 14, I was unable to find out how to render html markup into actual text. I used SwiftSoup to parse the HTML into a string, but it removed <br/> and it didn't parse it ...
  • 21
0 votes
0 answers
133 views

when converting HTML to Attributedstring, Bullet points and text are not aligned in RTL iOS swift

I am using localization(English and arabic).I need to convert HTML to attributed string, when it converting in arabic, content and Bullet points are not aligned RTL direction. now I am using code is : ...
2 votes
2 answers
366 views

Specifying NSLineBreakMode.byTruncatingTail causes issues when displaying NSAttributedString in UILabel

In my app, I fetch some HTML strings from the Wordpress REST API of a website. I use the following extension to convert the HTML to an NSAttributedString that I can display in my UILabel: extension ...
  • 25
1 vote
2 answers
820 views

NSAttributedString: how to parse html tags and add attributes

I have some localization strings like this: "Register and get <b>all</b>\n<b>rewards cards</b> of our partners\n<b>in one</b> universal <b>card</b>&...
  • 757
1 vote
0 answers
32 views

Set stroke color with NSAttributedString but get the wired result when text contains "2"/"6" [duplicate]

I want to set the border with white color to label texts, and I used the NSAttributedString, set both strokeWidth&strokeColor, but when I run the project, the result is too wired with text "2&...
  • 820
0 votes
0 answers
37 views

Hyperlink color in html NSAttributedString is not changing

I am converting html to NSAttributedString to show in UILabel. How to change the color of hyperlink, all other CSS added gets applied, only link is coming in blue color i.e. original color. Can we ...
  • 590
0 votes
0 answers
30 views

How to send NSAttributeString by using email composer?

Firstly, I convert the image into NSAttributeString, which that image could be insert to text view. And I'm trying to send this NSAttributeString by using email composer? I try to convert that ...

1
2 3 4 5
45