nsattributedstring

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

天大地大妈咪最大 提交于 2019-12-06 03:04:31
问题 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 alloc] initWithPath:path documentAttributes:NULL]; [creditsLabel setAttributedStringValue:as]; [creditsLabel becomeFirstResponder]; The hyperlinks in the window don't render in blue underline unless I first click somewhere on the NSTextField, as per the two screenshots. How can I make these

NSTextField (Label) Attributed Text: Select

时光怂恿深爱的人放手 提交于 2019-12-06 02:10:43
问题 I have a NSTextField Label that has attributed text in it. The color and size are different from the defaults. (The text is a bit larger and green) Now, I need to be able to select the text in the label so as the click the hyperlinks embedded in the attributed text. This works fine; however, when selecting the text the format of the text reverts back to the defaults (a smaller, black font). Is there anyway to stop this behavior so that my styling is preserved when the user clicks (selects

NSAttributedString to NSData No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes:

霸气de小男生 提交于 2019-12-05 22:55:39
问题 I am trying to convert NSAttributedString to NSData using RTFDFromRange method. Getting this: No visible @interface for 'NSAttributedString' declares the selector 'RTFDFromRange:documentAttributes: What is wrong with my code? NSAttributedString *val=self.textview.attributedText; NSData *data = [val RTFDFromRange:NSMakeRange(0, self.textview.text.length) documentAttributes:nil]; 回答1: NSAttributedString does not have a method called RTFDFromRange for iOS, but only for Mac OS X. To convert

TTTAttributedLabel “Read More >” tail truncation with several attributes possible?

核能气质少年 提交于 2019-12-05 22:35:26
TTTAttributedLabel support a custom truncation string via truncationTokenString as well as truncationTokenStringAttributes . However, I am wanting to go a bit further and set several string attributes on the truncation string, including different fonts and colours. This is what I am trying to achieve: The arrow at the end can be achieved using a font icon, so I was thinking of the following string: @"… Read More >" 'HORIZONTAL ELLIPSIS' (U+2026) + Read More + > character from a font . Unfortunately TTTAttributedLabel doesn't allow me to set the ranges for various attributes. Does anyone have a

UITextView lineHeightMultiple Clips Top, first line, of Text

房东的猫 提交于 2019-12-05 19:45:48
In iOS 8, I have a vanilla UITextView that clips the top of the 1st line when a lineHeightMultiple is applied to it's NSMutableParagraphStyle , see image below: It appears as though lineHeightMultiple affects the 1st line of text in addition to subsequent lines. Setting clipsToBounds = false on the UITextView will at least enable the clipped part to show, but you can see from the image below that now the top part of the text is obviously above it's frame: I can fix this by just setting the top constraint on the offending UITextView to compensate for clipsToBounds = false but that feels like a

CoreText and strikethrough on iPhone

徘徊边缘 提交于 2019-12-05 19:01:00
I'm currently struggling with the need to display strikethrough text in many UITableViewCell s. Something that written in HTML would looke like <strike>€99</strike> save 50% => now €49 I don't want to use a UIWebView just for a single line of text, especially that it's used in small UITableViewCell s. I know there are reusable cells and all, but I'd like to keep things the more memory-efficient way possible. So... I'm using NSAttributedString s, with the help of AliSoftware's UILabel -replacement OHAttributedLabel . The fact that it's only available starting with iOS 4.0 is no problem, as we

NSAttributedString change color at end of string

情到浓时终转凉″ 提交于 2019-12-05 18:49:43
问题 This must be an easy thing to do, but I cannot figure it out. I have a NSMutableAttributedString that has, for example, "This is a test" in it. I want to color the word "test" blue, which I do with this: NSMutableAttributedString *coloredText = [[NSMutableAttributedString alloc] initWithString:@"This is a test"]; [coloredText addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(10,4)]; That works just fine. But now I want to set the text color back to black

Split Attributed String and Retain Formatting

倾然丶 夕夏残阳落幕 提交于 2019-12-05 18:44:39
How can you take an existing NSAttributedString and divide it based on a predefined separator while maintaining formatting? It does not seem that componentsSeparatedByString will operate on an NSAttributedString. My current workaround produces the splits at the correct points, but only outputs an NSString. Thus losing formatting. NSData *rtfFileData = [NSData dataWithContentsOfFile:path]; NSAttributedString *rtfFileAttributedString = [[NSAttributedString alloc] initWithData:rtfFileData options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType} documentAttributes:nil error:nil]; NSString

How do I display a NSAttributedString on an iPhone? [duplicate]

◇◆丶佛笑我妖孽 提交于 2019-12-05 15:47:06
问题 This question already has answers here : iphone/ipad: How exactly use NSAttributedString? (9 answers) Closed 6 years ago . I believe I understand how to set NSAttributedString values but how on earth do you actually display them in the interface? examples: UILabel, UITextView, etc. Specific instructions would be greatly appreciated/ Thanks! 回答1: you could also create a CATextLayer, which works fine with attributed strings... Just create the layer, and set it's string property... Have fun...

Simple UIAlertView with NSAttributedString(s)

淺唱寂寞╮ 提交于 2019-12-05 10:09:48
I am looking for a simple way to use NSAttributedString with a very simple message box similar to: NSString *new_item = [NSString stringWithFormat:@"<span style=\"font-family: Helvetica Neue; font-size: 12.0\">%@</span>", @"MOTD HTML String downloaded from website"]; NSAttributedString * attrStr = [[NSAttributedString alloc] initWithData:[new_item dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType } documentAttributes:nil error:nil]; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MOTD" message:attrStr delegate:nil