nsattributedstring

Animated Gif inside UITextView

主宰稳场 提交于 2019-12-03 16:28:19
I had a look at this question and it didn't work. I am also trying to avoid this sort of solution. In the end I am willing to go with a CADisplayLink and change each frame manually. Still, is there a simpler way to do this? Bjørn Ruthberg An animated gif if just a collection of images which are displayed in sequence at a timed interval. You can do this with a UIImageView like this: imageView.animationImages = [UIImage(named: "uploadFrame0")!, UIImage(named: "uploadFrame1")!, UIImage(named: "uploadFrame2")!, UIImage(named: "uploadFrame3")!, UIImage(named: "uploadFrame4")!, UIImage(named:

Objective C - How to create rtf from NSAttributedString

大城市里の小女人 提交于 2019-12-03 16:27:49
I can convert from rtf string to attributed string using following: NSAttributedString *attributedStr = [[NSAttributedString alloc] initWithData:data options:@{NSDocumentTypeDocumentAttribute:NSRTFTextDocumentType} documentAttributes:nil error:nil]; Now how can i convert back from attributedString to rtf string? You want to use -dataFromRange:documentAttributes:error: NSAttributedString *str = [[NSAttributedString alloc] initWithString:@"YOLO" attributes:nil]; NSData *data = [str dataFromRange:(NSRange){0, [str length]} documentAttributes:@{NSDocumentTypeDocumentAttribute:

Is Rounded Corners on Attributed Text Background possible?

纵饮孤独 提交于 2019-12-03 16:02:13
I attributed Text with different textcolors. For better readability on highlighted text i use backgroundcolor. Is it possible to bring the CALayer Effect of Rounded Corners on this Textarea? Not the whole Area but the special Text inside of it. My Code: NSAttributedString *text = [[NSAttributedString alloc] initWithString:@"Highlighted Text" attributes:@{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:10.0f], NSForegroundColorAttributeName: [UIColor lightGrayColor], NSBackgroundColorAttributeName: [UIColor darkGrayColor] }]; 来源: https://stackoverflow.com/questions/19144145/is

NSAttributedString tail truncation in UILabel

三世轮回 提交于 2019-12-03 14:46:44
问题 I'm using ContextLabel to parse @ , # and URL's. This is the best solution i found, cause it sizes correctly and dont affect performance. It firstly parses string at input and than converts it to NSAttributedString and after this assigns it to attributedText property of UILabel . Everything works as expected, except tail truncation - it's very incorrect ( see pic below ) Where shall i start digging - is it wrong attributes on attributed string? Or label layout issue? Thanks! 回答1: I had this

HTML with <blockquote> tags in UITextView

£可爱£侵袭症+ 提交于 2019-12-03 14:38:32
I want to display HTML text with <blockquote> tags in the UITextView . example of HTML: <div> <blockquote class="uncited"> <div> <cite>Nick:</cite> <blockquote class="uncited"> <div> <cite>Tom:</cite>censored<br> Hello </div> </blockquote> <p>World</p> </div> </blockquote> <p>Text</p> </div> I use the following code to display HTML text in the cell: UITextView *textView = (UITextView*)[cell viewWithTag:100]; NSAttributedString *attributedString = [[NSAttributedString alloc] initWithData:[thisComment.htmlText dataUsingEncoding:NSUnicodeStringEncoding] options:@{ NSDocumentTypeDocumentAttribute:

NSAttributedString Color Test

家住魔仙堡 提交于 2019-12-03 14:12:23
What is the correct way to compare, or test, for a particular color attribute of an NSAttributed string? As an example, I'd like to know if the text selection has red text. I have tried several approaches, as you can see below, but none of them ever results in a match. I see the text turn red on screen, and logging the attribute returns: UIDeviceRGBColorSpace 1 0 0 1 - (BOOL)isRedWithAttributes:(NSDictionary *)attributes { BOOL isRedWithAttributes = NO; if (attributes != nil) { // if ( [attributes objectForKey:NSForegroundColorAttributeName] == [UIColor redColor] ) // if ( [attributes

-fontWithSize returning different font object

老子叫甜甜 提交于 2019-12-03 14:11:51
Update 1 I found a work-around: // instead of font = [font fontWithSize:pointSize]; // i can do this and get the correct font back font = [UIFont fontWithName:font.fontName size:pointSize] I'm using Nick Lockwood's HTMLLabel class to turn HTML into an NSAttributedString that respects the styling within the HTML. For the most part, it works great. However, I'm using a custom font in my app, and for some reason, my font is always getting rendered in bold. I don't have this problem using the system fonts. I've narrowed it down to this method: - (UIFont *)font { // ** Code Path 1 ** UIFont *font =

Draw a line inside a UITextView - NSAttributedString

a 夏天 提交于 2019-12-03 14:08:17
I wish to draw a customizable line inside a UITextView consisting of some text (using NSAttributedString ) Here's what I tried NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr]; NSRange strRange = NSMakeRange(0, str.length); NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init]; tabStyle.headIndent = 16; //padding on left and right edges tabStyle.firstLineHeadIndent = 16; tabStyle.tailIndent = -16; NSTextTab *listTab = [

NSAttributedString and html styling (bullet alignment)

强颜欢笑 提交于 2019-12-03 14:07:53
In my iOS app I'm using NSAttributedString to generate a list of bullets. Unfortunately I'm struggling with making the bullets look presentable. My first attempt was to use regular text and a unicode character for the bullets, basically using a string like this: var attributedString = NSMutableAttributedString( string: "Here is a list of bullets and a paragraph introducing them, note that this paragraph spans multiple lines\n" + "• This is the first bullet\n" + "• Here is a second bullet\n" + "• And here is a third bullet with a lot of text such that it overflows to the next line" ) The result

Different font size in the same label?

霸气de小男生 提交于 2019-12-03 13:40:55
Is it possible to have different fontsize or weight in the same UILabel? I can do it in the storyboard as Attributed label, but I need to do it programmatically. cell.lblOne.text = [NSString stringWithFormat: @"FontSize15:: %@, FontSize20:: %@",monkey, goat]; Edit: I saw something about NSAttributedString but I can't get it to work. foundry Take a look at my answer here: UITextView Alternative make an NSMutableAttributedString give it some attributes (applied to ranges of characters) set the label's attributedText property . NSMutableAttributedString *attString = [[NSMutableAttributedString