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
0
answers
86
views
Can I use an AttributedString to display a background color that extends to the end of the line?
I was trying to use an AttributedString to represent a diff. I used a red/green background color on the removed/added lines. I would like the background to extend until the end of the line (ie up to ...
0
votes
2
answers
132
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
225
views
UITextView from Markdown text
I'd like to use Markdown text in a UITextView. It looks simple, but I'm not getting the expected rendering of most elements.
let mdString = """
# Headline
This is a line.
* Bullet 1
* ...
2
votes
1
answer
153
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: ...
0
votes
0
answers
68
views
Navigation on substring swiftui
I want to implement a onTapGesture on multiple substrings of a string but keeping the whole text view appropiate.
For example the String is,
"By click on checkbox you agree to our terms of ...
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()
...
0
votes
1
answer
45
views
How to force hr separator using NSAttributedString to fill a requested width?
This is how I defined my separator:
extension NSAttributedString {
static var separator: NSAttributedString {
let attributes: [NSAttributedString.Key: Any] = [
....
1
vote
1
answer
140
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 ...
0
votes
2
answers
89
views
Unable to draw rounded stroke in NSAttributedString
I'm trying to apply a rounded stroke effect to text using NSMutableAttributedString in Swift. I have been able to find various NSMutableAttributedString.Key options for text attributes like color, ...
1
vote
0
answers
102
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 ...
0
votes
1
answer
133
views
How to add border and corner radius to selected range of text using attributes in NSAttributedString?
In my code I simply have:
let adminName = " ADMIN "
let name = [adminName, "Greg Weg"].joined(separator: " ")
let attributed = NSMutableAttributedString(...
1
vote
1
answer
112
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 ...
1
vote
1
answer
231
views
NSAttributedString attributes stripped after assigning to NSTextStorage
In the code below, I am loading a markdown string in NSAttributedString. One of the feature in the app needs functionality to convert NSAttributedString back to plain markdown text. To achieve that, I ...
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
1
answer
229
views
When using AsyncDisplayKit / Texture with an NSTextAttachment image in the attributed text of a ASTextNode, how to reload the ASTextNode?
I am able to demonstrate my issue with this simple example.
I am using AsyncDisplayKit / Texture in my iOS app.
I have a ASTableNode which shows attributed strings. These will have images in them via ...
0
votes
0
answers
175
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
votes
1
answer
332
views
How to Check If AttributedString isEmpty in SwiftUI
I have private var remark: AttributedString?, I want to check is remark is notEmpty then Show the View.
While debugging, I'm getting this
(lldb) po remark
▿ Optional<AttributedString>
▿ some : ...
1
vote
1
answer
93
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 ...
2
votes
1
answer
109
views
iOS: NSAttributedString - writing to data loses adaptive text color
I want to use text color in my NSTextVeiw / UITextView that adapts to the system appearance. Dark mode, white text, otherwise black text. I have the following NSAttributedString:
#if os(iOS)
let ...
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
0
answers
67
views
How to make attributed string never wrap?
I am using NSAttributedString for my NSTextView for showing a hyperlink along with some other string. when my other string is long the link string gets wrapped (i.e that's the link string breaks and ...
0
votes
1
answer
112
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, ...
0
votes
1
answer
127
views
textContainerInset affecting NSAttributedString's background color alignment
I'm working on a SwiftUI "live markdown editor" that formats and hides syntax in realtime as the user writes.
I'm using NSTextView and NSViewRepresentable, and conditionally applying ...
1
vote
1
answer
93
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
66
views
HTML Bullet point sin NSAttributedString alignment
I've tried so many of the other answers on here and none seem to work. This one seems closest but the solutions haven't helped. I'm displaying the following HTML (we get this back in a response):
<...
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
...
0
votes
0
answers
64
views
UIButton / Attributed Text - Varying line Spacing
I've got a component in a Swift 5 project inheriting from UIButton. The button has two sections of text: a heading (1 line) and a subheading (1+ lines). The two sections of text are formatted as a ...
2
votes
1
answer
636
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 &...
0
votes
0
answers
44
views
NSAttributedString html issue
When we are using nsattributedstring to render html we are seeing unnecessary gaps.
I tried using display mode inline tag. I have tried removing the '\n'. Many such things but html is rendering spaces ...
-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
2
answers
267
views
NSTextView with automatic fitting to content size
Main problem:
SwiftUI's Text() have no ability to fill large amounts of text inside. In case of text have too many symbols or in case of too large font it's displaying the following error:
[Window] ...
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
1
answer
143
views
Assertion failed: (forceBreakIndex > NSMaxRange(lastResortNode->lineBreak.range)), function -[_NSOptimalLineBreaker _calculateOptimalWrapping]
I found a bug which is to parse an HTML string with NSAttributedString and use it in a UITextView using AttributedText. The error is this:
Assertion failed:
(forceBreakIndex > NSMaxRange(...
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 ...
1
vote
1
answer
518
views
How to chain UIKit attributes of an AttributeContainer?
Starting in iOS 15, you can style text in UIKit with an AttributedString. You can treat the attributes as properties of the AttributedString, or you can make an AttributeContainer and treat the ...
2
votes
0
answers
880
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 |
| -------------...
0
votes
1
answer
267
views
What is needed in order to use NSAttributedString in a Swift application?
I am creating a simple application meant to read messages from the local iMessage database on OSX (macOS 13.4). These messages are stored as NSMutableAttributedStrings, which I understand to be a ...
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 ...
2
votes
0
answers
101
views
Handling multi-stage input language in UITextField
I have a regular UITextField in my view controller:
@IBOutlet private weak var textField: UITextField!
This text field has a delegate set to it, as well as an event listener. Whenever a text value ...
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
0
answers
197
views
Getting memory leak when converting HTML string to AttributedString
Getting memory leak when converting HTML string to AttributedString using below String extension
Usage:
self.lblHeader.attributedText = "<H1>Hello world</H1><h2><b>, abc&...
1
vote
2
answers
871
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 @...
1
vote
1
answer
479
views
How can I use NSParagraphStyle to create a bulleted list in UITextView?
I'm trying to support bulleted list formatting in a UITextView in my app. I've googled around and found various answers to questions (like here) that suggest using NSParagraphStyle. Right now to make ...
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'...
7
votes
1
answer
472
views
Negative baselineOffset values ignored on NSAttributedString (iOS 16.4+ only)
When building for iOS 16.4, we noticed different behavior when it comes to using baselineOffset on an NSAttributedString.
positive values are now handled differently than on previous iOS versions (no ...
0
votes
0
answers
74
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
...
4
votes
1
answer
2k
views
using baselineOffset in NSAttributedString problem in iOS 16.4
as you can see, after i build project on iOS 16.4 i faced a problem that baselineOffset is not like on iOS 16.0.
what should i do?
this is my code:
class ViewController: UIViewController {
@...
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 ...
1
vote
0
answers
208
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, ...