nsattributedstring

Apply Custom font to Attributed string Which Converts from HTML String

喜夏-厌秋 提交于 2019-12-17 11:45:50
问题 I used UITextView in which i display NSAttributedString . i got HTML string from server . I converted HTML to NSAttributedString using below code. NSMutableAttributedString *attrib = [[NSMutableAttributedString alloc]initWithData:[strHTML dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: @(NSUTF8StringEncoding)} documentAttributes:nil error:nil]; To Apply font i tried below 2 codes. apply Attribute

Saving custom attributes in NSAttributedString

為{幸葍}努か 提交于 2019-12-17 10:42:45
问题 I need to add a custom attribute to the selected text in an NSTextView. So I can do that by getting the attributed string for the selection, adding a custom attribute to it, and then replacing the selection with my new attributed string. So now I get the text view's attributed string as NSData and write it to a file. Later when I open that file and restore it to the text view my custom attributes are gone! After working out the entire scheme for my custom attribute I find that custom

Looping Through NSAttributedString Attributes to Increase Font SIze

大憨熊 提交于 2019-12-17 07:22:20
问题 All I need is to loop through all attributes of NSAttributedString and increase their font size. So far I got to the point where I successfully loop through and manipulate attributes but I cannot save back to NSAttributedString . The line I commented out is not working for me. How to save back? NSAttributedString *attrString = self.richTextEditor.attributedText; [attrString enumerateAttributesInRange: NSMakeRange(0, attrString.string.length) options:NSAttributedStringEnumerationReverse

Superscript cents in an attributed string

╄→尐↘猪︶ㄣ 提交于 2019-12-17 06:56:07
问题 I'm trying to get my label to look like so: But using attributed string, I managed to get this result: My code: NSString *string = [NSString stringWithFormat:@"%0.2f",ask]; NSMutableAttributedString *buyString = [[NSMutableAttributedString alloc] initWithString:string]; [buyString addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:15.0] range:NSMakeRange(2, buyString.length - 2)]; self.labelBuy.attributedText = buyString; As you see, the numbers after the dot, stay below, and I

NSAttributedString background color and rounded corners

放肆的年华 提交于 2019-12-17 02:27:10
问题 I have a question regarding rounded corners and text background color for a custom UIView . Basically, I need to achieve an effect like this (image attached - notice the rounded corners on one side) in a custom UIView: I'm thinking the approach to use is: Use Core Text to get glyph runs. Check highlight range. If the current run is within the highlight range, draw a background rectangle with rounded corners and desired fill color before drawing the glyph run. Draw the glyph run. However, I'm

How can I make a clickable link in an NSAttributedString?

守給你的承諾、 提交于 2019-12-16 20:55:50
问题 It's trivial to make hyperlinks clickable in a UITextView . You just set the "detect links" checkbox on the view in IB, and it detects HTTP links and turns them into hyperlinks. However, that still means that what the user sees is the "raw" link. RTF files and HTML both allow you to set up a user-readable string with a link "behind" it. It's easy to install attributed text into a text view (or a UILabel or UITextField , for that matter.) However, when that attributed text includes a link, it

Scroll UITextView to specific text

六眼飞鱼酱① 提交于 2019-12-14 01:14:08
问题 i have a uitextview with large texts and above i have a search field. Anything searched, i would love the uitextview to scroll to that specific text and hightlight. And i need to make sure that the uitextview scrolls in such a way that the searched text stays in the first line I populated the textview with attributed text with some attributes. What i tried is get the text before the target text and tried to get the size of it adding the exact attributes i added on textview text at the

Why does setting an attributedText's background raise an NSRangeException error?

China☆狼群 提交于 2019-12-13 21:57:25
问题 So I'm trying to set a blue background color to a UILabel 's attributed text dynamically as the user pans their finger along the screen but I can't for the life of me figure out why I'm getting an NSRangeException with the following error message: Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds at times. Here's my code: var afterContext = "" if textDocumentProxy.documentContextAfterInput != nil {

How to Show custom Emojis Url link in Labels iOS

半城伤御伤魂 提交于 2019-12-13 21:47:02
问题 How to show Emojis url link in label. Emojis Unicode format is showing properly but when we show emojis url link its not showing its show same URL link. I am using this code for showing Emojis:- NSString *html = msCommentObj.mCommentText; NSAttributedString *attr = [[NSAttributedString alloc] initWithData:[html dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute:@(NSUTF8StringEncoding)}

How to map HTML to in NSAttributedString in iOS

帅比萌擦擦* 提交于 2019-12-13 19:55:35
问题 Since the NSAttributedString initWithHTML addtion is only availiable on Mac OS but not iOS. 回答1: You should check Oliver Drobnik's NSAttributedString Additions for HTML project on GitHub. It is a response to precisely that problem. See also his blog post about it. 来源: https://stackoverflow.com/questions/4075223/how-to-map-html-to-in-nsattributedstring-in-ios