nsattributedstring

NSBackgroundColorAttributeName for multiline attributed strings labels

这一生的挚爱 提交于 2019-12-08 13:48:27
问题 I'm trying to display a map with information overlayed. To improve legibility on the map, I tried several ways (text shadows, outline text, darkening the map), but nothing really worked well – hence I tried to use a semitransparent box underneath the text. I'm using the NSBackgroundColorAttributeName , which – as you can see in the screenshot – works fine for single line labels. In the multiline case though, the box seems to fill a whole line, even if there are no characters above. Is this a

Append NSAttributed text to UITextview

坚强是说给别人听的谎言 提交于 2019-12-08 12:37:11
问题 I can't believe I am asking this question but (been looking for the answer for an hour and a half with no luck)... how do I append NSAttributedText to a UITextView? (in Swift 2.0+) I'm building a tool which downloads items from my server, and as they come in I want to add AttributedText with green for success or red color for fails. To do this I believe I need NSMutableAttributedString, but the UITextView only has NSattributedString which does not have access to the appendAttributedString

NSAttributedString clicks

。_饼干妹妹 提交于 2019-12-08 11:33:29
问题 I would like to have an attributed string in a NSTextView . The attributed string has 3 lines, each one a different color and no underline. I want to be able to click (or double click) on each line, which would print out the line number. 回答1: You can use the addAttribute:value:range of NSMutableAttributeString to assign the click behaviour to your attributed string. According to the documentation : Attributed String. When your string is clicked, it should call clickedOnLink:atIndex: of

NSAttributedString: Setting FontAttributes doesn't change font

ぃ、小莉子 提交于 2019-12-08 11:02:51
问题 I am trying to change the font on an NSAttributedString. I have a method which iterates over each character, and creates a new NSFontAttribute dictionary for that character. In the end, however, the string remains un-changed. To demonstrate, here is how I setup the string: UIFontDescriptor *fontDescriptor = [UIFontDescriptor fontDescriptorWithName:@"Avenir-Book" size:14.0f]; NSDictionary *fontAttributes = [fontDescriptor fontAttributes]; [fontAttributes setValue:[NSString stringWithFormat:@"

How to use NSSuperscriptAttributeName for OS X

人走茶凉 提交于 2019-12-08 09:31:31
问题 I can change the font and size but I'm stuck with making text a superscript. Here is my working code for font and size: aVerseMutableString = NSMutableAttributedString(string: book.verseText, attributes: [NSFontAttributeName:NSFont(name: "Helvetica", size: 18.0)!]) Here is what I'm trying for superscript that's not working: aVerseNumberMutableString = NSMutableAttributedString(string: verseNumber.description, attributes: [NSSuperscriptAttributeName:NSNumber(1)!]) I'm not sure how to do the

Swift 3.1 - NSSuperScript in NSAttributedString not working as expected

谁说我不能喝 提交于 2019-12-08 06:56:33
问题 The application I am working on encountered an issue when testing with iOS 10.3 Simulator via XCode 8.3 beta 2, where the superscript in AttributedString displayed on the same line with normal text. For iOS 10.2.x and below, it is displaying correctly. iOS 10.3 screenshot: https://www.dropbox.com/s/p5v71g722cg5qhy/Screen%20Shot%202017-02-21%20at%2010.24.21%20AM.png?dl=0 iOS 10.2.x and below screenshot: https://www.dropbox.com/s/lcfsic6xyz953qp/Screen%20Shot%202017-02-21%20at%2010.19.17%20AM

Swift 3.0 convert Double() to NSMutableAttributedString

余生颓废 提交于 2019-12-08 06:28:27
问题 in advance thanks for help. I am trying to make calculator application (for specific purposes) and I would like to know, if there exist a way how to convert Double() to NSMutableAttributedString. I need this for label output answer. Reason of using NSMutableAttributedString is because I would like to have answer with subscripts and upper-scripts. //example of my code var a = Double(), b = Double(), c = Double() a = Double(textField1.text!) b = Double(textField2.text!) c = a + b let font

Using core text on Mac book pro / HD screen different text sizes

微笑、不失礼 提交于 2019-12-08 05:57:41
问题 I've recently shifted to a MacBook Pro 15" and core text is behaving strangely. I have an app that uses core text to draw an NSattributedstring with CTFrameDraw. It works as expected on the external 1080p monitor, if I drag the window across to the MacBook Pro screen then the font is displayed very tiny like it's changed from 10 point font to 5 point when painted. Likewise if I repaint the text on the MacBook Pro then it's still small. I'd guess it's because the MacBook Pro has the high

Can I get the position of elements in NSAttributedString?

╄→尐↘猪︶ㄣ 提交于 2019-12-08 04:13:45
问题 I use NSAttributeString to get something like above(include normal text ,underlined text and images) , and now I want do : if the user tapped on the underlined text area , I will do some special actions (open the web or sth). Now i can get the location of touches already , but can i find the locations (or area) of the underlined text ? so I can use both area to judge the tap position is located on underline text or not? 回答1: As per my understanding you can UItextview and its delegate will

Vertically aligning NSTextAttachment in NSMutableAttributedString

别来无恙 提交于 2019-12-08 04:10:57
问题 I'm adding an icon to a UILabel using NSTextAttachment inside an NSMutableAttributedString like this: //Setting up icon let moneyIcon = NSTextAttachment() moneyIcon.image = UIImage(named: "MoneyIcon") let moneyIconString = NSAttributedString(attachment: moneyIcon) //Setting up text let balanceString = NSMutableAttributedString(string: " 1,702,200") balanceString.insert(moneyIconString, at: 0) //Adding string to label self.attributedText = balanceString self.sizeToFit() But for some reason the