nsattributedstring

NSAttributedString superscript styling

假装没事ソ 提交于 2019-11-26 09:34:53
问题 I want to superscript all the instances of ® character in a block of text (legal disclaimer, naturally ;)) and the default way NSAttributedString is not very good. If I just let the character be and only use unmodified NSString , it is rendered the same size as a capital letter and is placed approximately at the baseline. If I add the superscript attribute to NSAttributedString as follows: [attrStr setAttributes:@{(NSString *)kCTSuperscriptAttributeName : @1} range:NSMakeRange(locationOfReg,

Wrapping Text in a UITextView Around a UIImage WITHOUT CoreText

只谈情不闲聊 提交于 2019-11-26 09:27:02
问题 Is there a way to wrap text from a UITextView around a UIImage without using CoreText ? I have been playing around with attributed strings without much luck, and CoreText just seems extremely complicated so I would rather stay out of it. 回答1: This seems to do the trick: UIBezierPath * imgRect = [UIBezierPath bezierPathWithRect:CGRectMake(0, 0, 100, 100)]; self.textView.textContainer.exclusionPaths = @[imgRect]; Works only from iOS 7 and up. 回答2: The short answer is you can't without CoreText

Example of NSAttributedString with two different font sizes?

≡放荡痞女 提交于 2019-11-26 09:26:40
问题 NSAttributedString is just really impenetrable to me. I want to set a UILabel to have text of different sizes, and I gather NSAttributedString is the way to go, but I can\'t get anywhere with the documentation on this. I would love it if someone could help me with a concrete example. For instance, let\'s say the text I wanted was: (in small letters:) \"Presenting The Great...\" (in huge letters:) \"HULK HOGAN!\" Can somebody show me how to do that? Or even, a reference that\'s plain and

NSAttributedString, change the font overall BUT keep all other attributes?

≯℡__Kan透↙ 提交于 2019-11-26 09:02:37
问题 Say I have an NSMutableAttributedString . The string has a varied mix of formatting throughout: Here is an example: This string is hell to change in iOS , it really sucks . However, the font per se is not the font you want. I want to: for each and every character, change that character to a specific font (say, Avenir) BUT, for each and every character, keep each of the other attributions (bold, italic, colors, etc etc) which was previously in place on that character. How the hell do you do

Is it possible to change color of single word in UITextView and UITextField

安稳与你 提交于 2019-11-26 09:01:45
问题 Is it possible to change color of single word in UITextView and UITextField ? If i have typed a word with a symbol infront (eg: @word) , can it\'s color be changed ? 回答1: Yes you need to use NSAttributedString for that, find the RunningAppHere. Scan through the word and find the range of your word and change its color. EDIT: - (IBAction)colorWord:(id)sender { NSMutableAttributedString * string = [[NSMutableAttributedString alloc]initWithString:self.text.text]; NSArray *words=[self.text.text

boundingRectWithSize for NSAttributedString returning wrong size

不想你离开。 提交于 2019-11-26 07:53:03
问题 I am trying to get the rect for an attributed string, but the boundingRectWithSize call is not respecting the size I pass in and is returning a rect with a single line height as opposed to a large height (it is a long string). I have experimented by passing in a very large value for the height and also 0 as in the code below, but the rect returned is always the same. CGRect paragraphRect = [attributedText boundingRectWithSize:CGSizeMake(300,0.0) options:NSStringDrawingUsesDeviceMetrics

Add “…Read More” to the end of UILabel

一世执手 提交于 2019-11-26 07:37:42
问题 I have a UILabel and in some cases the text is longer then the UILabel itself, so I see the text as \"bla bla bla...\" I want to add a ...Read More button text at the end of the UILabel .. I\'ve read some posts but they offer solutions that are not good to me, for example: to calculate how many characters will enter the UILabel , but with the font i\'m using each character has a different width. How can I manage to do that? Thanks in advance! 回答1: Swift4 (IOS 11.2) Readmore at the end of the

UILabel and NSLinkAttributeName: Link is not clickable

给你一囗甜甜゛ 提交于 2019-11-26 07:34:50
问题 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

How to make subscripts and superscripts using NSAttributedString?

风格不统一 提交于 2019-11-26 07:30:43
问题 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? 回答1: 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

How do I make an attributed string using Swift?

纵饮孤独 提交于 2019-11-26 05:42:33
问题 I am trying to make a simple Coffee Calculator. I need to display the amount of coffee in grams. The \"g\" symbol for grams needs to be attached to my UILabel that I am using to display the amount. The numbers in the UILabel are changing dynamically with user input just fine, but I need to add a lower case \"g\" on the end of the string that is formatted differently from the updating numbers. The \"g\" needs to be attached to the numbers so that as the number size and position changes, the \