nsattributedstring

Swift : tap on a part of text of UILabel

╄→гoц情女王★ 提交于 2019-11-26 20:27:12
问题 I have a problem that "boundingRectForGlyphRange" always returns CGRect.zero "0.0, 0.0, 0.0, 0.0". "boundingRectForGlyphRange" is not working. For example, I am coding for touching on a part of text of UILabel feature. My text has first part is "any text" and second one is "READ MORE". I want the tap recognizer only work when I touch "READ MORE". If I touch on any point on UILabel, "CGRectContainsPoint" always return true,then the action called Here my code: override func viewDidLoad() {

UILabel and NSLinkAttributeName: Link is not clickable

Deadly 提交于 2019-11-26 20:24:11
I want to use attributed strings with NSLinkAttributeName to create clickable links inside a UILabel instance within my iOS 7 project, which is now finally possible without using external libraries. NSURL *url = [NSURL URLWithString:@"http://www.google.com"]; NSDictionary *attr = [NSDictionary dictionaryWithObjectsAndKeys: url, NSLinkAttributeName, nil]; Applying the attribute on a string displays the text as blue & underlined, but nothing happens on click/tap. User interaction is enabled for the label. Does anybody know how to do this? Thanks! max.mustermann I can answer my own question now:

How to make subscripts and superscripts using NSAttributedString?

送分小仙女□ 提交于 2019-11-26 20:09:15
I need to make subscripts for chemistry formulas (H2O, Na^2+, etc)? Is this possible to do with NSAttributedString, or is there an alternative/easier way to make subscripts? This is possible to do with NSAttributedString . The attribute constant you're looking for depends on your platform. For Mac OS X it is NSSuperscriptAttributeName and on iOS it is kCTSuperscriptAttributeName . Pass in a negative value for subscript. The only caveat is that UILabel on iOS can't draw NSAttributedString s (yet, fingers crossed for iOS 6). You would need to draw the text using Core Text or find some third

Use multiple font colors in a single label

↘锁芯ラ 提交于 2019-11-26 19:41:02
Is there a way to use two, or even three font colors in a single label in iOS? If the text "hello, how are you" were used as an example, the "hello," would be blue, and the "how are you" would be green? Is this possible, it seems easier than creating multiple labels? Kirit Modi First of all initialize of you NSString and NSMutableAttributedString as below. var myString:NSString = "I AM KIRIT MODI" var myMutableString = NSMutableAttributedString() In ViewDidLoad override func viewDidLoad() { myMutableString = NSMutableAttributedString(string: myString, attributes: [NSFontAttributeName:UIFont

UILabel with two different color text

核能气质少年 提交于 2019-11-26 18:29:32
问题 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. 回答1: 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

how to resize an image or done as a NSAttributedString NSTextAttachment (or set its initital size)

血红的双手。 提交于 2019-11-26 17:46:56
问题 I have a NSAttributedString to which I am adding a NSTextAttachment. The image is 50w by 50h but I'd like it to scale down to reflect the line height of the attributed string. I thought this would be done automatically but I guess not. I have looked at the UImage class reference but this image doesn't seem to be set in a UIImageView so no access to a frame property. Here's a screenshot of what I currently have: In an ideal world, I would also like to implement a way to scale up the image

How can I both stroke and fill with NSAttributedString w/ UILabel

﹥>﹥吖頭↗ 提交于 2019-11-26 17:40:32
问题 Is it possible to apply both stroke and fill with an NSAttributedString and a UILabel ? 回答1: Yes, the key is to apply a Negative value to the NSStrokeWidthAttributeName If this value is positive you will only see the stroke and not the fill. Objective-C: self.label.attributedText=[[NSAttributedString alloc] initWithString:@"string to both stroke and fill" attributes:@{ NSStrokeWidthAttributeName: @-3.0, NSStrokeColorAttributeName:[UIColor yellowColor], NSForegroundColorAttributeName:[UIColor

Convert attributed string, to, “simple” tagged html

我只是一个虾纸丫 提交于 2019-11-26 17:29:12
问题 I want to convert an NSAttributedString, to html like this: This is a <i>string</i> with some <b>simple</b> <i><b>html</b></i> tags in it. Unfortunately if you use apple's built-in system it generates verbose css-based html. (Example below for reference.) So how to generate simple tagged html from an NSAttributedString? I wrote a very verbose, fragile call to do it, which is a poor solution. func simpleTagStyle(fromNSAttributedString att: NSAttributedString)->String { // verbose, fragile

Swift- Change font on an HTML string that has its own Styles

只谈情不闲聊 提交于 2019-11-26 17:27:28
问题 I am dinamically getting an HTML string from a Wordpress API and parsing it into an Attributed String to show it in my app. Since the string has its own styles, it shows different fonts and sizes, something that is affecting our design choices. What I want to do is change the font and its size on the whole attributed string. I tried doing so in the options of the attributed string, but it does nothing: let attributedT = try! NSAttributedString( data: nContent!.decodeHTML().data(using: String

Two colors for UILabel TEXT

爱⌒轻易说出口 提交于 2019-11-26 16:57:06
问题 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"