nsattributedstring

Change attributes of substrings in a NSAttributedString

故事扮演 提交于 2019-12-29 14:21:11
问题 This question may be a duplicate of this one. But the answers don't work for me and I want to be more specific. I have a NSString , but I need a NS(Mutable)AttributedString and some of the words in this string should be given a different color. I tried this: NSString *text = @"This is the text and i want to replace something"; NSDictionary *attributes = @ {NSForegroundColorAttributeName : [UIColor redColor]}; NSMutableAttributedString *subString = [[NSMutableAttributedString alloc]

How do I create a UIColor from RGBA?

非 Y 不嫁゛ 提交于 2019-12-29 12:12:33
问题 I want to use NSAttributedString in my project, but when I'm trying to set color, which isn't from the standard set ( redColor , blackColor , greenColor etc.) UILabel displays these letters in white color. Here is my line of this code. [attributedString addAttribute:NSForegroundColorAttributeName value:[UIColor colorWithRed:66 green:79 blue:91 alpha:1] range:NSMakeRange(0, attributedString.length)]; I tried to make color with CIColor from Core Image framework, but it showed the same results.

Applying different attributes for different portions of an NSAttributedstring

主宰稳场 提交于 2019-12-29 08:05:11
问题 I know it is possible to apply attributes to an NSAttributedString. But how can we apply different attributes to same attributed string. for the string "This is an attributed text." How can we set a particular attribute(background color or foreground color) to "This is" another attribute(background color or foreground color) to "an attributed text." Is there any way to achieve this....? Also is there any way to set the background color of an NSAttributedString in iOS? 回答1: Make a mutable copy

NSAttributedString from HTML in the background thread

孤街醉人 提交于 2019-12-29 07:54:06
问题 What I need is to create NSAttributedString objects from relatively big HTML strings and store them (NSAttributedString-s) in the database. And of course I would like to do that in the background thread. Here is a simple code (which fails) to demonstrate what I'm trying to do: dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ NSString *HTMLString = @"<p>HTML string</p>"; NSDictionary *options = @{NSDocumentTypeDocumentAttribute : NSHTMLTextDocumentType,

NSMutableAttributedStrings - objectAtIndex:effectiveRange:: Out of bounds

你说的曾经没有我的故事 提交于 2019-12-28 22:02:08
问题 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 =

iOS 7 BUG - NSAttributedString does not appear

时间秒杀一切 提交于 2019-12-28 04:00:33
问题 Last week I asked a question about a Simulator bug with NSAttributedString not displaying: iOS 7 Simulator Bug - NSAttributedString does not appear Unfortunately it now appears this is not a simulator bug but an iOS 7 bug. I have now reproduced this issue on an iPhone 5 device. The bug appears to be the combination of using NSUnderlineStyleAttributeName & NSParagraphStyleAttributeName as attributes for a NSAttributedString. I have only tested on two iOS 7 devices so far, and the issue has

How to underline a UILabel in swift?

心已入冬 提交于 2019-12-28 03:31:05
问题 How to underline a UILabel in Swift? I searched the Objective-C ones but couldn't quite get them to work in Swift. 回答1: You can do this using NSAttributedString Example: let underlineAttribute = [NSUnderlineStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue] let underlineAttributedString = NSAttributedString(string: "StringWithUnderLine", attributes: underlineAttribute) myLabel.attributedText = underlineAttributedString EDIT To have the same attributes for all texts of one UILabel, I

More time is taken to display NSAttributed string with custom fonts

三世轮回 提交于 2019-12-25 15:56:43
问题 I am displaying NSAttributed string column wise using Core Text. It is working fine. When using system font, it is displayed without any delay both in simulator and device. But when using custom font, more time is taken to display the content in device. But in the simulator, the result is quick. - (void)updateAttributedString { // Existing Code if (self.text != nil) { self.attributedString = [[NSMutableAttributedString alloc] initWithString:self.text]; NSRange range = NSMakeRange(0, [self

NSAttributedString height limited by width and numberOfLines

大兔子大兔子 提交于 2019-12-25 08:29:15
问题 I need to calculate text rect in my custom label not using UILabel's sizeThatFits method. Code below not working correctly. The main idea is find CTLine at index = numberOfLines - 1 and return its max y position. But as a result text height sometimes too large and sometimes not enough to draw last line. - (CGSize)fittingSizeWithSize:(CGSize)size numberOfLines:(NSInteger)numberOfLines { if (numberOfLines == 0) { return [self fittingSizeWithSize:size]; } CTFramesetterRef framesetter =

How to increase the font size of a NSAttributedsString in iOS

醉酒当歌 提交于 2019-12-25 04:23:05
问题 I am trying to change the font size of an NSAttributedString dynamically. The problem is the string contains different font sizes and properties. so when i change the font size all the content size change to tat value. Not changing accordingly . .. . . 回答1: If I understood you correctly this approach should help you: you can enumerate all NSFontAttributeName attributes for your AttributedString and increase the font size by for instance 1. This would give you the following result: If that's