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
Filter by
Sorted by
Tagged with
0 votes
1 answer
220 views

NSMutableAttributedString not rendering correctly

I am using a SplitViewController; The master is tableView with a series of RightDetail cells whose Attributed Strings are set via a callback from a value setting popover. The value passed back and ...
1 vote
1 answer
164 views

Aligning substrings in NSAttributedString

I'm writing an attributed string to a UITextView. It has a left-aligned text substring, followed by a line number. I want that line number to be right-aligned. I tried applying an NSParagraphStyle to ...
4 votes
1 answer
2k views

Replacing NSAttributedString in NSTextStorage Moves NSTextView Cursor

I followed this tutorial and created a Mac version of it. It works pretty well, except there's a bug I can't figure out. The cursor jumps to the end of the string if you try editing anything in the ...
-2 votes
1 answer
908 views

How do you bold the first line in an NSMutableParagraphStyle?

I have a class called "rectangle" to make custom UILabels. I override "draw" in the rectangle class. When I instantiate the label, I want the FIRST line of text to show up in bolded font. I know how ...
0 votes
1 answer
825 views

HTML Text (with Table) in UILabel using NSAttributedString

I was trying to load a simple html string (which has a table) on the UILabel using the attributed string, if the language is english it works well for the rtl layouts the formatting does not work, but ...
2 votes
1 answer
163 views

I'm unable to enumerate an NSAttributed Text in Swift 3

I'm unable to get this to compile correctly in swift 3. I'm running into the issue of Actual code here. i'm not sure why it is asking for an extra , in the code data2 = items.data(using: .utf8) ...
9 votes
2 answers
6k views

NSAttributedString with tabs

How do you create a UILabel with this kind of text format? Would you use NSAttributedString?
5 votes
1 answer
1k views

Unable to enable letter spacing (kerning) on UITabBarItem

I am trying to enable Text Kerning (increase Letter spacing) on UITabBarItem title labels. But providing the NSKernAttributeName attribute for the UITabBarItem does not make any difference. The other ...
2 votes
1 answer
582 views

How to fix in transform NSAttributedString from html string in swift?

When I convert html string to NSAttributedString, it works well normally but I have a problem in specific cases. func htmlAttributed(family: String?, size: CGFloat, color: UIColor) -> ...
0 votes
1 answer
43 views

UILabel Will Not Update with Timer

I tried to use this code to update the time of a uilabel of a custom cell every time the time changes by a minute. override func viewWillAppear(_ animated: Bool) { super.viewWillAppear(true) ...
2 votes
1 answer
294 views

How to Fix "Upside Down" / "Inverted" / "Flipped" Text in placeholderAttributedString of NSTextField

I've already figured out the solution. However, I couldn't find anything that addressed the problem. Problem: I wanted to customize the placeholder text in NSTextField, but it would appear upside ...
-1 votes
1 answer
75 views

In UITextfield, When applying color using NSMutableAttributedString the color is not applied correctly when unfocusing

Using NSMutableAttributedString, I applied color for a specific character in a string using UITextfield. My Code: uITextField = new UITextField(); uITextField.BackgroundColor = UIColor.LightGray; ...
0 votes
1 answer
198 views

Open link on a text set to UILabel as attributed string. Attributed string is read from a json response

I am reading this json response in my tableview cell. I have set this to a UILabel and managed to show this as attributed sting to my label. My view is showing the text inside the tags as link but ...
0 votes
3 answers
2k views

Change the colour of the bullets in UITextView

I am using a UITextView to display a text which I get from a API call. From the text I need to identify the special character ","(comma) and replace it with a newline escape sequence and green ...
4 votes
1 answer
328 views

NSAttributedString to HTML to NSAttributedString color degradation

I have a rich text editor in which the user can edit font, color etc. The model keeps this information in memory as an instance of NSAttributedString. When i want to store this info and write to disk, ...
7 votes
6 answers
6k views

NSMutableAttributedString's attribute NSStrikethroughStyleAttributeName doesn't work correctly in iOS8

I have a mutable attributed string without NSStrikethroughStyleAttributeName attribute like this: NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:@"aaaa" ...
3 votes
3 answers
1k views

Html Data to JSON to String Using Swift 4 [duplicate]

I am trying to decode html data to simple string but I get all html syntax along with I am using alamofire get method Link for html data http://laorotava.municipiointeligente.es/webservices/...
20 votes
4 answers
23k views

Cannot convert value of type 'Range<String.Index>' (aka 'Range<String.CharacterView.Index>') to expected argument type 'NSRange' (aka '_NSRange')

I am trying to replace a substring with attributed String. Following is my code. let searchText = self.searchBar.text! let name = item.firstName ?? "" let idNo = "Employee Id. \(item.employeeId ?? "...
5 votes
1 answer
2k views

NSAttributedString text always sticks to bottom with big lineHeight

I'm trying to implement by-design labels coming from Sketch e.g. I need text styles with font size = 19 and line height = 50. So I ended up using NSAttributedString with NSMutableParagraphStyle but ...
1 vote
1 answer
563 views

What's the default kerning for UILabel (attributed text looks different)

I'm not sure if I'm missing something obvious but I've looked around on SO and couldn't find an answer. Basically, despite what this question says, UILabel plain text and attributed text looks ...
-1 votes
1 answer
37 views

NSAttributedString not returning expected value

I am trying to create text like: "bill started following you." and make the username semibold. I tried this but doing .string gives me a weird long string. How can I fix it? //let nUsername = ...
0 votes
1 answer
260 views

How to split NSAttributedString across equal bounds views with correct word wrap

I have been grappling with this since a while. There are APIs that give us bounds size for given attributes of NSAttributedString. But there is no direct way to get string range that would fit ...
5 votes
2 answers
4k views

NSAttributedString: underline is not applied

I'm trying to add underline style for UITextView and it's not applied. If i use "shadow" (uncomment shadow styling and comment underline styling) i can see it, but no underline is applied for some ...
0 votes
2 answers
271 views

I need help removing underscore after formatting a string

When a string starts and ends with an underscore, I am making that string italic. After that, I am removing the underscores. This works fine if the string is like this "_hello_ world" However, this ...
1 vote
1 answer
47 views

Set font for single word in title of UINavigationController

I have a UINavigationController that is set with prefersLargeTitles = true I would like to set the title so that rather than Discogs | Search Box it reads Discogs | Search Box I cannot see how ...
2 votes
1 answer
819 views

UILabel with NSAttributedString returns incorrect boundingRect value

func calculateSizeFor(label:UILabel, attributedText: NSAttributedString) -> CGSize { let constraint:CGSize = CGSize(width: label.frame.size.width, height: ....
2 votes
3 answers
1k views

Exception is not being caught

Crashlytics reports that the following line is sometimes throwing a NSInternalInconsistencyException: let attrStr = try NSMutableAttributedString( data: modifiedFont.data(using: String....
0 votes
1 answer
146 views

Create attributed text of placeholder's values in a String

I got this String: let someString = String(format: NSLocalizedString("%1$@ changed your user role %2$@.", comment: ""), username, userRole) I want to make the userRole bold. That could be done with ...
1 vote
1 answer
940 views

NSAttributedString: how to make multiline in another NSAttributedString

I am trying to create a multiline separate text in another text to achieve the below text style. I have tried the below code to produce the goal but the third part of the code is creating a issue (...
30 votes
2 answers
13k views

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

iOS change the color of links for uilabel when using NSAttributedString

I'm using a uilabel and adding a link to by using NSAttributedString let attributedText = NSMutableAttributedString(string: "http://www.google.com") attributedText.addAttributes([...
0 votes
1 answer
200 views

Fontsize of attributedString doesn't change

I have an attributedString and want to change only it's fontsize. To do that, I use another method that I found on StackOverflow. For most cases, this is working, but somehow it doesn't change the ...
21 votes
4 answers
17k views

Add NSUnderlineStyle.PatternDash to NSAttributedString in Swift?

I'm trying to add an underline to some text in my Swift app. This is the code I have currently: let text = NSMutableAttributedString(string: self.currentHome.name) let attrs = [...
0 votes
1 answer
139 views

AttributedString in UITextView is trimmed at the top

I am using attributed string in UITextView. Sample playground can be found here This is a quick summary of what is happening. UITextView has padding issue which can be solved using this thanks to @...
1 vote
1 answer
3k views

Swift NSAttributedString add table

I am trying to programmatically build attributed string with table in it. I figured out it's very easy if I first create HTML like this: let html = """ <table style="height: 51px;" width="147"> ...
1 vote
1 answer
2k views

swift: The HTML data converted to NSAttributed string doesn't make the links clickable in label

I have a text in HTML format. I am using the property of NSAttributed string to parse it. It pareses the text nicely and displays on the label. However, the parsing of the anchor tag doesn't make the ...
5 votes
2 answers
2k views

Why do hyperlinks sometimes not show in an NSTextField with an NSAttributedString?

The text I use in an NSTextField is loaded from a file as follows. NSString *path = [[NSBundle mainBundle] pathForResource:@"Credits" ofType:@"rtf"]; NSAttributedString *as = [[NSAttributedString ...
0 votes
1 answer
254 views

Read text from all rtf files in directory and create master file swift

Context I have an app where the user can write multiple 'scenes'. These are saved as separate file. I need to offer the user 2 options for exporting (to export all scenes individually or all together ...
1 vote
1 answer
587 views

UITextView/NSAttribute: Detect if word starts with a particular symbol

I've been looking for a way to change the text in a UITextView when a word begins with either "@" or "#". I found this code snippet below on StackOverflow which works perfectly if you type "Hello" or "...
0 votes
1 answer
468 views

Unable to render an NSAttributedString as a 2 column tabbed bullet list in a PDF

I am constructing a large string that is output into a PDF file, but right now, I'd like to have a 2 column, bulleted list in my document. However, I have yet to figure out the correct settings that ...
8 votes
1 answer
3k views

Swift: NSAttributedString & emojis

I use a UITextView with text attributes editing enabled and I am having issue with getting the attributes when there are emojis in the text. Here is the code I use: var textAttributes = [(attributes: [...
0 votes
0 answers
156 views

Support fonts set dynamically in UITextView attributed string

I have to support rich text in UITextView. I unable to show different parts of the the text set in different fonts types and sizes. I already tired using document type NSAttributedString....
0 votes
1 answer
211 views

NSAttributedString: How do you add BOLD to a customized (e.g., Palatino) font?

Below are some customized extension functions for the NSAttributedString class for the Palatino font: extension NSAttributedString { class func blueAttributeStringOf(string:NSString) -> ...
4 votes
2 answers
731 views

NSAttributedString and emoji: the range I never set seems to be set

This is the most weird problem (XCode 10.2.1 playground): let a = "String with emoji 🔑" var b = "00:00 0000" var nsa = NSMutableAttributedString(string: a) var nsb = NSMutableAttributedString(...
1 vote
1 answer
3k views

Custom Attributed string action in swift

I want to make the attributed string action in swift. I want append my custom variable to table view cell data. I added colour and line also for that string, now i want to add the link for that added ...
2 votes
1 answer
253 views

Convert attributed text to HTML

In my case I have to convert NSHTMLTextDocumentType document to NSMutableAttributedString for which I use below snippet [[NSMutableAttributedString alloc] initWithData:[text dataUsingEncoding:...
25 votes
2 answers
3k views

Setting NSUnderlineStyle causes unrecogognized selector exception

I am trying to underline a string with NSAttributed string. For some reason, my lines cause the exception: -[_SwiftValue _getValue:forType:]: unrecognized selector sent to instance The result is ...
1 vote
1 answer
438 views

Add Nsattributed string and string in swift

I having the Dynamic data, I load that data into tableview but these data having the mixing of Attributed and normal strings. Here I getting the as "Tap here" ,I want to dilate that string with Blue ...
-2 votes
1 answer
960 views

SVG NSTextAttachment text encoding issue

To be able to use SVG images for an attributed string created fom HTML, I do func createAttributedString(string: String) -> NSMutableAttributedString { let data = string.dataUsingEncoding(...
3 votes
2 answers
844 views

Use NSAttributedString multiple times in one string

I have a string, for example "F (R U R' U') (R U R' U') (R U R' U') F'". I am using NSAttributedString to search for the text in brackets (R U R' U') and replace it with the same text, just in a ...

1
10 11
12
13 14
46