Questions tagged [nsmutableattributedstring]

357 questions
5
votes
0 answers

Rounded corners with NSMutableAttributedString

My question I think is very simple but I couldn't find anything with Google. I am using NSMutableAttributedString to modify styles in a string and for example I use this code to change the background color: [string…
Juan
  • 77
  • 3
  • 7
5
votes
3 answers

Animate a change in part of an NSMutableAttributedString

I'm making an iOS app that has a UITextView. When closing a parenthesis in that UITextView, I want to highlight to the user which opening parenthesis it pairs to. So far I've done this using an NSMutableAttributedString and changing the font size of…
Andreas
  • 151
  • 2
  • 9
5
votes
2 answers

iOS - How to use `NSMutableString` in swift

I have seen this Objective-C code but I'm struggling to do the same in swift: NSMutableAttributedString *res = [self.richTextEditor.attributedText mutableCopy]; [res beginEditing]; __block BOOL found = NO; [res…
Steve Gailey
  • 129
  • 1
  • 10
5
votes
1 answer

iOS: Change NSMutableAttributedString's Font Height Without Changing Font Width?

I have an NSMutableAttributedString "timeString" whom's font and color I have already set. Everything is working fine, but I was wondering if there were a way to alter the text's height without changing the text's width (font width = 100%, font…
KingPolygon
  • 4,753
  • 7
  • 43
  • 72
5
votes
2 answers

Extract the last 50 lines from an NSAttributedString

Is there a simple way to split a NSAttributedString so I get only the last 50 or so lines? NSMutableAttributedString *resultString = [receiveView.attributedText mutableCopy]; [resultString appendAttributedString:[ansiEscapeHelper…
David Karlsson
  • 9,396
  • 9
  • 58
  • 103
4
votes
2 answers

adjustsFontSizeToFitWidth does not work properly with NSMutableAttributedString on iOS 14

I need to reduce the text size in order to fit a specific area width. The text contains some different format settings (mainly text color) so I am using NSMutableAttributedString Then I set adjustsFontSizeToFitWidth for fitting with the bounding…
cristallo
  • 1,951
  • 2
  • 25
  • 42
4
votes
2 answers

NSMutableAttributedString with different fonts

I have a problem with the combination of two strings: let finalMutableString = NSMutableAttributedString() let attributedDot = NSAttributedString(string: " ●", attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 7)]) let firstPartString =…
4
votes
3 answers

how can I change style of pre-selected words in my textView?

This is a follow up to this question How can I change style of some words in my UITextView one by one in Swift? Thanks to @Josh's help I was able to write a piece of code that highlights each word that begins with # - and do it one by one. My final…
user3766930
  • 5,629
  • 10
  • 51
  • 104
4
votes
1 answer

How to change colour of the certain words in label - Swift 3

Created a Label with a simple text. How can I change the color of the certain words in the label? Swift 3 Like below-
Eugene Or
  • 53
  • 1
  • 6
4
votes
1 answer

How to use System Font with an Attributed String?

let attributedText: NSMutableAttributedString = NSMutableAttributedString(string: text, attributes: [NSFontAttributeName: UIFont(name: "San Francisco", size: 14.0)!]) Using the code above, when I run my app it crashes because it cannot find the…
Schuey999
  • 4,706
  • 7
  • 21
  • 36
4
votes
1 answer

Adding attributes to attributed text in Swift

I tried to add attributes to a text label: let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = NSTextAlignment.Center let para = NSMutableAttributedString() let font:UIFont? = UIFont(name: "DIN Alternate", size: 18.0) let…
AVEbrahimi
  • 17,993
  • 23
  • 107
  • 210
4
votes
1 answer

How do you remove and replace an NSTextAttachment in an NSAttributedString

I have a mutable attributed string which I have added an image text attachment to. NSMutableAttributedString* attributedString = [_textField.attributedText mutableCopy]; NSMutableDictionary* dict =…
4
votes
1 answer

NSMutableAttributedString - NSShadow without border

I tried out NSMutableAttributedString to stylise my font with this code: NSMutableAttributedString* attString = [[NSMutableAttributedString alloc] initWithString:element04.text]; NSRange range = NSMakeRange(0, [attString length]); …
sooon
  • 4,718
  • 8
  • 63
  • 116
4
votes
2 answers

Setting kCTUnderlineStyleAttributeName for an NSMutableAttributedString in Swift

The documentation for kCTUnderlineStyleAttributeName relays the following: kCTUnderlineStyleAttributeName The style of underlining, to be applied at render time, for the text to which this attribute applies. Value must be a CFNumber object.…
Kyle G
  • 4,347
  • 4
  • 26
  • 39
4
votes
1 answer

Button action or similar in NSAttributedString

Is there a way to do something similar to the attribute NSLinkAttribute but instead of open an url I want trigger an action on iOS? [attributedString addAttribute:NSLinkAttributeName value:@"http://www.google.com" range:range];
flopes
  • 1,345
  • 1
  • 14
  • 21