nsattributedstring

Change the color of a link in an NSMutableAttributedString

别等时光非礼了梦想. 提交于 2019-11-28 18:06:27
I have the following code but my links are always blue. How do I cange the color of them? [_string addAttribute:NSLinkAttributeName value:tag range:NSMakeRange(position, length)]; [_string addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:(12.0)] range:NSMakeRange(position, length)]; [_string addAttribute:NSStrokeColorAttributeName value:[UIColor greenColor] range:NSMakeRange(position, length)]; _string is a NSMutableAttributedString and the position and length work fine. Swift Updated for Swift 4.2 Use linkTextAttributes with a UITextView textView

How do you stroke the _outside_ of an NSAttributedString?

牧云@^-^@ 提交于 2019-11-28 17:59:45
I've been using NSStrokeWidthAttributeName on NSAttributedString objects to put an outline around text as it's drawn. The problem is that the stroke is inside the fill area of the text. When the text is small (e.g. 1 pixel thick), the stroking makes the text hard to read. What I really want is a stroke on the outside. Is there any way to do that? I've tried an NSShadow with no offset and a blur, but it's too blurry and hard to see. If there was a way to increase the size of the shadow without any blur, that would work too. NSGod While there may be other ways, one way to accomplish this is to

iOS NSAttributedString to HTML

為{幸葍}努か 提交于 2019-11-28 17:54:32
I have an NSAttributed string (coming from HTML) that I set for a UITextView . - (void)setHtml:(NSString *)html { NSData *htmlData = [html dataUsingEncoding:NSUTF8StringEncoding]; // Create the HTML string NSDictionary *importParams = @{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType}; NSError *error = nil; self.htmlString = [[NSAttributedString alloc] initWithData:htmlData options:importParams documentAttributes:NULL error:&error]; self.editorView.attributedText = self.htmlString; } I then let the user edit what they want, and I would like to then convert it out to HTML again, so I

NSParagraphStyle line spacing ignored

与世无争的帅哥 提交于 2019-11-28 17:12:18
问题 A simple test that is failed: Make a new project with just one subview (UITextView) and put the following in: - (void)viewDidLoad { [super viewDidLoad]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineHeightMultiple = 50.f; paragraphStyle.lineSpacing = 100.f; paragraphStyle.minimumLineHeight = 200.f; paragraphStyle.maximumLineHeight = 500.f; UIFont *font = [UIFont fontWithName:@"AmericanTypewriter" size:24.f]; self.textView.attributedText =

Core Text - NSAttributedString line height done right?

↘锁芯ラ 提交于 2019-11-28 15:56:40
问题 I'm completely in the dark with Core Text's line spacing. I'm using NSAttributedString and I specify the following attributes on it: - kCTFontAttributeName - kCTParagraphStyleAttributeName From this the CTFrameSetter gets created and drawn to context. In the paragraph style attribute I'd like to specify the height of the lines. When I use kCTParagraphStyleSpecifierLineHeightMultiple each line receives padding at the top of the text, instead of the text being displayed in the middle of this

NSAttributedString add text alignment

不羁的心 提交于 2019-11-28 15:55:52
How can I add text alignment attribute to an NSAttributedString to center the text? Edit: Am I doing anything wrong? It doesn't seem to change the alignment. CTParagraphStyleSetting setting; setting.spec = kCTParagraphStyleSpecifierAlignment; setting.valueSize = kCTCenterTextAlignment; CTParagraphStyleSetting settings[1] = { {kCTParagraphStyleSpecifierAlignment, sizeof(CGFloat), &setting}, }; CTParagraphStyleRef paragraph = CTParagraphStyleCreate(settings, sizeof(setting)); NSMutableAttributedString *mutableAttributed = [[NSMutableAttributedString alloc] initWithAttributedString:self

Paste Formatted Text, Not Images or HTML

亡梦爱人 提交于 2019-11-28 13:54:27
I am trying to emulate the pasteboard behavior of the iOS Pages and Keynote apps. In short, allowing basic NSAttributedString text formatting (i.e. BIU) to be pasted into a UITextView, but not images, HTML, etc. BEHAVIOR SUMMARY If you copy formatted text from the Notes app, Evernote, or text and images from a web site, Pages will only paste the plain text string If you copy formatted text from within Pages or Keynote, it will paste the formatted text elsewhere in Pages, Keynote, etc. An undesired consequence, but perhaps important to acknowledge, is that neither Notes app or Evernote will

Calculate the range of visible text in UILabel

橙三吉。 提交于 2019-11-28 13:54:00
I have an UILabel with fixed size, the text that I set into this UILabel can be 200, 5 or 500 characters long. What I want to do is to calculate how much visible text can I put into this UILabel with the current UILabel size. Why I want to do that? Because I want to add a ...Read more text at the end of the text, but not at the end of the whole text, just at the end of the visible text in the UILabel . Thanks in advance. So I've created a method which returns the current visible string height (with the size of the UITextView / UITextField or UILabel) and it's also support iOS6+, this is what I

NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

感情迁移 提交于 2019-11-28 12:04:51
I'm trying to add some fancy text to a label, but I've run into some problems with the NSMutableAttributedString class. I was trying to achieve four this: 1. Change font, 2. Underline range, 3. Change range color, 4. Superscript range. This code: - (void)applicationDidFinishLaunching:(NSNotification*)aNotification { NSMutableAttributedString* display = [[NSMutableAttributedString alloc] initWithString:@"Hello world!"]; NSUInteger length = [[display string]length] - 1; NSRange wholeRange = NSMakeRange(0, length); NSRange helloRange = NSMakeRange(0, 4); NSRange worldRange = NSMakeRange(6, length

How to add Underline/Bold/Italicize Abilities for UITextView Swift [duplicate]

丶灬走出姿态 提交于 2019-11-28 11:52:07
问题 This question already has answers here : How to add toggleBoldface option to a UITextView in iOS? (2 answers) Closed last year . I have been searching for quite a while for a solution as to how to grant users the ability to underline, italicize and bold text in a UITextView but have not been able to find a solid solution. I have realized that I will need to use an NSAttributedString but am not sure as to how to create the UI and format the string so I am able to save it to a database. If you