nsattributedstring

How to set color of templated image in NSTextAttachment

五迷三道 提交于 2019-12-03 09:37:05
How can I set the color of a templated image that is an attachment on an attributed string? Background: I've got a UILabel and I'm setting its attributedText to an NSAttributedString. The NSAttributedString includes an NSTextAttachment with a small image. Now I want to make my image color match the text color and I can't figure out how to make it work. I would normally expect to color the image by setting its rendering mode to UIImageRenderingModeAlwaysTemplate and then setting the tintColor on the containing UIView. I've tried setting the tintColor on my UILabel but that has no effect. Here's

Appending NSAttributedString with line break returns attributed string with wrong format

岁酱吖の 提交于 2019-12-03 09:36:05
I'm using NSMutableAttributedString and NSAttributedString to display a label text in two different font sizes. My approach is: NSMutableAttributedString *muAtrStr = [[NSMutableAttributedString alloc]initWithString:@"2"]; NSAttributedString *atrStr = [[NSAttributedString alloc]initWithString:@"days" attributes:@{NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Bold" size:8]}]; [muAtrStr appendAttributedString:atrStr]; Which returns me an Attributed string with "2" in font size 12 and "days" in font size 8. However, the other scenario is to add a line break after 2. I use the

NSAttributedString end of first line indent

假如想象 提交于 2019-12-03 08:36:41
I want to have the first line in an NSAttributedString for a UITextView indented from the right side on the first line. So the firstLineHeadIndent in NSParagraphStyle will indent the first line from the left. I want to do the same thing but from the right in my UITextView . Here's a screenshot of how I want the text to wrap. The Setting Text Margins article from the Text System User Interface Layer Programming Guide has this figure: As you can see, there's no built-in mechanism to have a first line tail indent. However, NSTextContainer has a property exclusionPaths which represents parts of

Saving NSAttributedString with NSTextAttachment into file. How to?

不羁的心 提交于 2019-12-03 08:27:17
I have a NSTextView , which may contains rich text or rich text with image as NSTextAttachment . There is how I adds attachment: NSImage *image = [NSImage imageNamed:@"image"]; NSTextAttachmentCell *attachmentCell =[[NSTextAttachmentCell alloc] initImageCell:image]; NSTextAttachment *attachment =[[NSTextAttachment alloc] init]; [attachment setAttachmentCell: attachmentCell ]; NSAttributedString *attributedString =[NSAttributedString attributedStringWithAttachment: attachment]; [[aTextView textStorage] beginEditing]; if ([aTextView shouldChangeTextInRange:NSMakeRange([aTextView selectedRange]

create an attributed string out of plain (Android formatted) text in swift for iOS

♀尐吖头ヾ 提交于 2019-12-03 08:15:49
I am reading strings out of a Localizable.strings which contains something like that which is basically what you have in an strings.xml of an Android app "testShort" = "A <b>short</b>\ntest with another<b>bold text</b>"; The bold and and line feed are the only two formatting attributes I have in my texts. I am trying to develop a method like this for days now without success: func ConvertText(inputText: String) -> NSAttributedString { // here comes the conversion to a representation with Helvetica 14pt and Helvetica-Bold 14pt including line feeds. } My final goal is to display the text in an

UITextView with NSAttributedString and custom attributes not working

允我心安 提交于 2019-12-03 07:11:46
When using a UITextView I try to add a custom attribute to an attributed string. However, all custom keys are lost after assigning to a UITextView's attributedText. Like this: NSMutableAttributedString *lString = [[ NSMutableAttributedString alloc ] initWithString: @"astring" attributes: @{ @"customkey": @"customvalue" }]; NSLog(@"string: %@", lString); // shows customkey present textView.attributedText = lString; NSLog(@"result: %@", self.textView.attributedText); // shows customkey missing Is this supposed to work? rmaddy Based on the comments, you are trying to misuse NSAttributedString .

UITextView linkTextAttributes font attribute not applied to NSAttributedString

谁说我不能喝 提交于 2019-12-03 05:57:08
问题 I have an NSAttributedString generated from HTML which includes some links. The attributed string is shown in a UITextView. I wish to apply a different font style for the links and am setting linkTextAttributes for this. I've added NSForegroundColorAttributeName , NSFontAttributeName and NSUnderlineStyleAttributeName . For some reason the foreground color is applied but the remaining attributes are not. myTextView.linkTextAttributes = [NSForegroundColorAttributeName : UIColor.redColor(),

Really close lines with NSAttributedString?

こ雲淡風輕ζ 提交于 2019-12-03 05:46:08
问题 I want to have two lines of text appear really close together (small line spacing) for a button. I have the following code: NSMutableAttributedString *string = [[NSMutableAttributedString alloc] initWithString:@"50 WPM"]; NSMutableParagraphStyle *paragrapStyle = [[NSMutableParagraphStyle alloc] init]; paragrapStyle.alignment = NSTextAlignmentCenter; paragrapStyle.lineSpacing = -10; [string addAttribute:NSParagraphStyleAttributeName value:paragrapStyle range:NSMakeRange(0, string.length)];

NSAttributedString and emojis: issue with positions and lengths

人盡茶涼 提交于 2019-12-03 05:09:49
问题 I'm coloring some parts of a text coming from an API (think "@mention" as on Twitter) using NSAttributedString. The API gives me the text and an array of entities representing the parts of the text that are mentions (or links, tags, etc) which should be colored. But sometimes, the coloration is offset because of emojis. For example, with this text: "@ericd Some text. @apero" the API gives: [ { "text" : "ericd", "len" : 6, "pos" : 0 }, { "text" : "apero", "len" : 6, "pos" : 18 } ] which I

Display NSAttributedString using CoreText

匆匆过客 提交于 2019-12-03 03:14:31
I have heard that I can display a NSAttributedString using CoreText, can anyone say me how (The simplest way)? Please, don't answer with CATextLayer or OHAttributedLabel. I know that there are a lot of questions about this in this forum, but I haven't find the answer Thanks!! I think that the simplest way (using Core Text) is: // Create the CTLine with the attributed string CTLineRef line = CTLineCreateWithAttributedString(attrString); // Set text position and draw the line into the graphics context called context CGContextSetTextPosition(context, x, y); CTLineDraw(line, context); // Clean up