nsattributedstring

Color attribute is ignored in NSAttributedString with NSLinkAttributeName

北城以北 提交于 2019-11-28 00:55:13
In an NSAttributedString , a range of letters has a link attribute and a custom color attribute. In Xcode 7 with Swift 2, it works: In Xcode 8 with Swift 3, the custom attributed color for the link is always ignored (it should be orange in the screenshot). Here's the code for testing. Swift 2, Xcode 7: import Cocoa import XCPlayground let text = "Hey @user!" let attr = NSMutableAttributedString(string: text) let range = NSRange(location: 4, length: 5) attr.addAttribute(NSForegroundColorAttributeName, value: NSColor.orangeColor(), range: range) attr.addAttribute(NSLinkAttributeName, value:

Transform an NSAttributedString to plain text

隐身守侯 提交于 2019-11-27 22:56:24
问题 I have an instance of NSData containing attributed text ( NSAttributedString ) originating from an NSTextView . I want to convert the attributed string to a plain string ( NSString ) without any formatting to do some text analysis (at the moment of conversion I do not have access to the originating NSTextView nor its NSTextStorage instance). What would be the best way to do this? EDIT: Out of curiosity I examined the result of: [[[self textView] textStorage] words] which appeared to be a

Are there any analogues of [NSString stringWithFormat:] for NSAttributedString

◇◆丶佛笑我妖孽 提交于 2019-11-27 21:46:58
问题 Usually I build app interface in interface builder. Sometimes design requires to use attributed strings (fonts, colors and etc.). It's easy to configure if string is static. But if string is dynamic (format with arguments) then there are no ways to configure attributes in interface builder. It requires to write a lot of code. I am looking for some analogues of [NSString stringWithFormat:] for NSAttributedString . So I will be able to set string format and necessary attributes in interface

Paste Formatted Text, Not Images or HTML

穿精又带淫゛_ 提交于 2019-11-27 19:30:38
问题 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

How could you make a uilabel wrap around an image (like shown)

依然范特西╮ 提交于 2019-11-27 18:07:52
问题 How could you achieve this effect: Maybe some sort of NSAtributedString? I have thought of hacky ways to just add spaces, but it needs to do it dynamically based on the width of the image. Any ideas? NOTE happily you can do this very easily with UITextView: https://stackoverflow.com/a/20033752/294884 this question is about UILabel. 回答1: Add image in your label with text as below code: NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:@"Here is

How to calculate the height of an NSAttributedString with given width in iOS 6 [duplicate]

∥☆過路亽.° 提交于 2019-11-27 18:05:30
Possible Duplicate: How to get height for NSAttributedString at a fixed width Now NSAttributedString is available in iOS 6. For layout purposes, I want to know how to calculate the required height of an NSAttributedString under fixed width. I'm looking for something that's equivalent to NSString's - (CGSize)sizeWithFont:(UIFont *)font constrainedToSize:(CGSize)size but for NSAttributedString. To calculate the drawing size of NSAttributedStrings, there are two methods available: - (CGSize)size can't be used because it does not take any width into consideration. I tried - (CGRect

iOS NSAttributedString on UIButton

℡╲_俬逩灬. 提交于 2019-11-27 17:41:18
I'm using iOS 6 , so attributed strings should be easy to use, right? Well... not so much. What I want to do: Using a custom subclass of UIButton (it doesn't do anything custom to titleLabel ), I'd like to have a multi-line, attributed title that is: All caps (I realize that's not part of the attributes) on the first line Bolded on the first line Underlined on the first line "Normal" weight on the second line Non-underlined on the second line Centered on both lines I've been able to get #'s 1 through 5 so far (at least, I thought I did, but current testing is yielding errors with multi-line

UILabel with two different color text

Deadly 提交于 2019-11-27 15:15:05
How can i have a UILabel with two different colors for the font? I will have text in two different strings and i want to make text with first string as red and second as green . The length of both the string is variable. You can't do this within a UILabel s. But my suggestion is that instead of using multiple UILabel just concentrate on NSAttributedString . Find UIControllers that draw NSAttributedString because UILabel , UITextView do not support NSAttributedString . PS: if you plan to distribute an iOS6 or later application, as UILabel now support NSAttributedString, you should use UILabel

Two colors for UILabel TEXT

五迷三道 提交于 2019-11-27 14:53:08
I want to set two colors for UILabel's text. I tried TTTRegexAttributedLabel , but it is throwing unknown type error. I tried following code too. But it is crashing at settext. NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"Hello. That is a test attributed string."]; [str addAttribute: @"Hello" value:[UIColor yellowColor] range:NSMakeRange(3,5)]; [str addAttribute:@"That" value:[UIColor greenColor] range:NSMakeRange(10,7)]; [str addAttribute:@"Hello" value:[UIFont fontWithName:@"HelveticaNeue-Bold" size:20.0] range:NSMakeRange(20, 10)]; [syncStatusLabel

HTML to NSAttributedString and NSAttributedString to HTML

倾然丶 夕夏残阳落幕 提交于 2019-11-27 14:49:25
i have a problem with NSAttributedString ... I want to convert a HTML string into an NSAttributedString and then work on the NSAttributedString (change some colors, fontsize, fontfamily, background- , foreground-Color) and then convert back plain HTML text from the NSAttributedString. Converting isn't a problem , but on each time I convert HTML to NSAS and back the fontsize getting bigger and bigger ?! Here is a picture and source code of my playground. // Playground - noun: a place where people can play // NSAS: - NSAttributedString import UIKit class Wrapper { //MARK: fields let apiHtml = "