2,264 questions
1
vote
2
answers
85
views
How do I re-use code that draws onto a macOS GraphicsContext to draw onto an UIKit context?
The different coordinate systems of Cocoa and UIKit cause problem when drawing a string in a UIGraphicsContext.
I have written code for macOS, where I draw a combination of primitives, attributedText, ...
0
votes
2
answers
125
views
iOS UITextView rich text with tags
I want to implement a UITextView whose content consists of plain text and tags, where the tags are text with a rounded gray background.
I tried to use NSAttributedString, but it cannot set rounded ...
2
votes
1
answer
148
views
Swift 6 concurrency issue with `NSTextAttachmentViewProvider`
I completely stuck with subclass NSTextAttachmentViewProvider in swift 6 concurrency.
So lets say I have a simple custom NSTextAttachmentViewProvider:
final shapeViewProvider: ...
6
votes
3
answers
1k
views
Why is NSAttributedString formatting html list <ol><li> incorrectly
I'm upgrading my project to Xcode 16. When using the following function, it renders correctly with Xcode 15 but it is not on Xcode 16.
// The label created with `attributedText`.
let label = UILabel()
...
1
vote
1
answer
138
views
Make a subtext tappable with dropdown?
We have previously solved similar issues like: SwiftUI tappable subtext
But how do you make subtext tappable, and also pop a dropdown at it's location when tapped? Do we need to use a webview? Split ...
1
vote
0
answers
97
views
NSAttributedString link color not changing in swift
Im working on an IOS app using swift and facing an issue with NSAttributedString where im trying to apply a hyperlink to a substring of a text. The hyperlink is functional but the link color remains ...
1
vote
1
answer
107
views
How to make an overlay for an image inside HTML text in NSAttributedString using CSS
I'm trying to parse html text that contains a youtube video. To display this video I use a preview image.
Initial text:
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod ...
0
votes
1
answer
47
views
HTML tags in UILabel don't work and instead got shown
I've got this HTML text:
"<style>* {font-size: 12pt !important;color: #000000 !important;font-family: Montserrat-Regular !important;}</style>Perform the following steps:<br><...
0
votes
0
answers
171
views
App crashes when I try to convert HTML string to NSAttributedString - "NSInternalInconsistencyException"
App crashes when I try to convert HTML string to NSAttributedString and assign it to a textView.
@IBOutlet weak var standingBillerNoteTextView: UITextView!
self.standingBillerNoteTextView....
1
vote
1
answer
87
views
Is there an option to apply single strikethrough line for NSMutableAttributedString with different fonts?
I have an NSAttributedString with two different font sizes for displaying currency in pennys.
I need to apply strikethrough to all strings, but not to break line of strikethrough.
How can I draw a ...
0
votes
0
answers
89
views
Why fonts loaded using CoreText (CTFont) behave different than loaded using AppKit (NSFont)?
I tried to load font using CTFontCreateWithFontDescriptor() and it behaves differently than loaded using NSFont(). Let's say the goal is to load font using CoreText that is exactly the same as using ...
0
votes
1
answer
111
views
Why am I seeing different behavior in macOS 14 when creating NSAttributedString from HTML vs doing the same thing with initWithString:attributes:?
I let my user choose a font from their installed fonts, then use that font in three different contexts in my macOS app.
The list of fonts itself uses NSFontDescriptor to create an attributed string, ...
1
vote
1
answer
87
views
SwiftUI value not getting updated
I have a SwiftUI Texteditor and whenever I press the update button the color should be applied to the text however it just gets reseted to initialValue. Can anyone help me?
import SwiftUI
class ...
0
votes
0
answers
112
views
Why when creating NSAttributedString from html sometimes app throws exception "The file couldn’t be opened because it isn’t in the correct format."
I have these extensions to parse string with html tags to NSAttributedString
extension StringProtocol {
var html2AttributedString: NSAttributedString? {
Data(utf8).html2AttributedString
...
2
votes
1
answer
618
views
How do you set the size of a view based NSTextAttachment?
I am attempting to make something that would make it possible to add custom UIView subclasses as attachments in UITextView. As of iOS 15, there appears to be an API that allows you to register custom &...
-1
votes
3
answers
92
views
How can I change the font after "," in string
I have a string value containing an amount, where I specified the decimal part as after "," and I want to change the font of the part after "," to be half of the other part
private ...
0
votes
0
answers
43
views
When using Core Text to draw an NSAttributedString, why is my text drawn repeated?
I have an NSLayoutManager subclass, overriding - (void)drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(CGPoint)origin and i'm trying to draw the NSAttributedString with CoreText.
This is what i ...
1
vote
0
answers
215
views
Instantiating "HTML-styled" NSAttributedString in a View's body produces weird behaviour
In an attempt to expose the capabilities of NSAttributedString in combination with UITextView to the world of SwiftUI (specifically the ability to render basic HTML), I've wrapped UITextView in a ...
2
votes
0
answers
874
views
How to copy to clipboard a Markdown formatted string using Swift?
I'm using the MarkdownUI library and through it I can create a markdown rendering as follows:
let someText = "
# Title
## Description
## Tables
| Left columns | Right columns |
| -------------...
1
vote
1
answer
174
views
Create attributed string based on cell type in Swift
I am currently developing a Notifications list screen that would display 4 types of notifications. Here is how it would look like in a very simple way:
The main problem for me is to make the text ...
0
votes
1
answer
1k
views
SwiftUI: How to open links in app instead of Safari using AttributedString
I have a FAQ page with cells that have a title as a String and a description as an AttributedString so that I can customize the appearance of the link in description. How can I open a link in an app ...
1
vote
2
answers
870
views
Tappable Substrings In SwiftUI
I have posts on my app where users can tag other users, the expectation is that these tags should be tappable and trigger a function when tapped.
For example the post: "hello @someUser and @...
0
votes
1
answer
1k
views
Creating an inline text link that will open up another view in my application
I'm trying to create a view in my app that displays a chunk of text. I want certain words within that text to be a clickable link that opens up another view. I've been googling for a long time and can'...
0
votes
0
answers
69
views
NSTextView ligature attribute overridden
When setting the .ligature attribute on an NSTextView, it gets overridden when adding both a .paragraphStyle and .baselineOffset attribute at the same time. Here's the example, adding the below code
...
15
votes
1
answer
2k
views
Using `NSTextAttachment` in SwiftUI `Text`
Does SwiftUI Text not work with NSTextAttachment? I have this AttributedString:
var attributedString: AttributedString {
var sampleAttributedString = AttributedString(sampleText)
// Apply some ...