nsattributedstring

Top-aligning text of different sizes within a UILabel

我怕爱的太早我们不能终老 提交于 2019-12-20 10:06:12
问题 How to top-align text of different sizes within a UILabel? An example is top-aligning smaller-sized cent amount with larger-sized dollar amount in price banners. UILabel in iOS6 supports NSAttributedString which allows me to have text of different sizes in the same UILabel. However it doesn't seem to have an attribute for top-aligning text. What are the options to implement this? It seems to me that providing a custom drawing logic to do top-alignment based on a custom attributed string key

NSAttributedString ignores Autoshrink and numberOfLines for UILabel (iOS 6)

别说谁变了你拦得住时间么 提交于 2019-12-20 08:48:21
问题 I have UILabel with number of lines = 2 system font size = 15 minimum font size = 8 Line break mode - Truncate tail When I set long text which have type NSString for UILabel it works fine and shows multiline text (scaled if needed). When I am trying to set text with type NSAttributedString it ignores minimum font size and Autoshrink so I see one line text with maximum font size. Is it possible to solve this problem Looks something like this (Label size is const) ----------------------- |

Getting the range of links in attributed string

不羁岁月 提交于 2019-12-20 06:19:55
问题 I would like to find the range of links in attributed text, so I could apply custom underline only to the relevant words. At the moment, the underline is under all of the text. I want it to be only under the links. The code is a bit complex as the requested underline is super customised. import UIKit class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() let text = "random text <a href='http://www.google.com'>http://www.google.com </a> more random text" let

How to implement a horizontal rule in a text view?

北城余情 提交于 2019-12-20 04:39:12
问题 Say I have an NSTextView (or a UITextView on iOS) and I want the user to be able to insert horizontal divider rules, like the HTML <hr> tag or this thing: What's the best way to implement this? Apple's documentation is very thing on this. So far, I have two ideas: Insert an NSTextAttachment for each rule and make the layout manager draw it somehow. Instead of a single text view, use multiple text views with scrolling disabled, put them in a stack view, add separator views between them and

Scrolling through UITableView causes Exception and Crash only on iPhone 5C

人盡茶涼 提交于 2019-12-20 01:35:15
问题 There is an exception being thrown when a user scrolls through my UITableView too fast or taps the status bar to jump to the top of the table. I am only seeing this crash on an iPhone 5C device. I can't reproduce it on the 4S, 5, or with the 32-bit simulator. Using the "All Exceptions" breakpoint, I was able to print out all the backtraces I could incrementing the frame pointer through the crash. Because there is no trace of my app in the backtrace (besides the main), I assume this is an

Scrolling through UITableView causes Exception and Crash only on iPhone 5C

霸气de小男生 提交于 2019-12-20 01:34:07
问题 There is an exception being thrown when a user scrolls through my UITableView too fast or taps the status bar to jump to the top of the table. I am only seeing this crash on an iPhone 5C device. I can't reproduce it on the 4S, 5, or with the 32-bit simulator. Using the "All Exceptions" breakpoint, I was able to print out all the backtraces I could incrementing the frame pointer through the crash. Because there is no trace of my app in the backtrace (besides the main), I assume this is an

How to replace a text attachment with a custom drawing with NSLayoutManager?

≡放荡痞女 提交于 2019-12-19 08:28:11
问题 My ultimate goal is to give the user the ability to split a text inside an NSTextView or UITextView into several sections , where two subsequent sections are visually separated by a custom view separator (possibly, but not necessarily a horizontal rule – I want to be able to adjust the visual appearance of the separator without a hassle). I need a solution that works on both platforms: macOS and iOS . (My related question focused on a solution for macOS and there is one that makes use of

How to create a subscript with NSAttributedString

谁说胖子不能爱 提交于 2019-12-19 07:06:31
问题 I see for NSAttributedString has a specific attribute for superscript, but I can't find one for subscript. What is the general practice for using NSAttributedString to create a subscript character? Example: H2O 回答1: Try NSSuperscriptAttributeName with a negative value. Failing that, the hard way would be to replace [0123456789] characters with [₀₁₂₃₄₅₆₇₈₉] in the string. 回答2: I struggled with subscripts/superscripts in NSMutableAttributedString for a while because the most basic solutions

Find last visible line index in NSAttributedString's drawWithRect

纵饮孤独 提交于 2019-12-19 04:19:06
问题 I am creating a pdf from user provided text, however I have an issue when the text is too big for the page, I have to calculate where the text would be cut off so I can move the next chunk to the next page. I use this code to draw the attributed text: CGRect rect = CGRectFromString(elementInfo[@"rect"]); NSString *text = elementInfo[@"text"]; NSDictionary *attributes = elementInfo[@"attributes"]; NSAttributedString *attString = [[NSAttributedString alloc] initWithString:text attributes

NSMutableAttributedString's attribute NSStrikethroughStyleAttributeName doesn't work correctly in iOS8

青春壹個敷衍的年華 提交于 2019-12-18 13:27:53
问题 I have a mutable attributed string without NSStrikethroughStyleAttributeName attribute like this: NSMutableAttributedString *str1 = [[NSMutableAttributedString alloc] initWithString:@"aaaa" attributes:@{NSStrikethroughStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle]}]; and another mutable attributed string with NSStrikethroughStyleAttributeName attribute like this: NSMutableAttributedString *str2 = [[NSMutableAttributedString alloc] initWithString:@"bbbb"]; and a whole