nsattributedstring

iOS7 UITextView set NSLinkAttributeName attribute but can not click

跟風遠走 提交于 2020-01-01 06:46:30
问题 @interface ViewController ()<UITextViewDelegate> - (void)viewDidLoad { [super viewDidLoad]; NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:@"www.google.com"]; NSDictionary *linkDic = @{ NSLinkAttributeName : [NSURL URLWithString:@"http://www.google.com"] }; [str setAttributes:linkDic range:[[str string] rangeOfString:@"www.google.com"]]; _textView.attributedText = str; } - (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)URL inRange:

-fontWithSize returning different font object

99封情书 提交于 2020-01-01 05:26:20
问题 Update 1 I found a work-around: // instead of font = [font fontWithSize:pointSize]; // i can do this and get the correct font back font = [UIFont fontWithName:font.fontName size:pointSize] I'm using Nick Lockwood's HTMLLabel class to turn HTML into an NSAttributedString that respects the styling within the HTML. For the most part, it works great. However, I'm using a custom font in my app, and for some reason, my font is always getting rendered in bold. I don't have this problem using the

Draw a line inside a UITextView - NSAttributedString

有些话、适合烂在心里 提交于 2020-01-01 05:09:49
问题 I wish to draw a customizable line inside a UITextView consisting of some text (using NSAttributedString ) Here's what I tried NSString *unicodeStr = [NSString stringWithFormat:@"%C%C%C", 0x00A0, 0x0009, 0x00A0]; //nbsp, tab, nbsp NSMutableAttributedString *str = [[NSMutableAttributedString alloc] initWithString:unicodeStr]; NSRange strRange = NSMakeRange(0, str.length); NSMutableParagraphStyle *const tabStyle = [[NSMutableParagraphStyle alloc] init]; tabStyle.headIndent = 16; //padding on

CGRect for selected UITextRange adjustment for multiline text?

和自甴很熟 提交于 2019-12-31 20:49:05
问题 I've used this answer in order to create a CGRect for a certain range of text. In this UITextView I've set it's attributedText (so I've got a bunch of styled text with varying glyph sizes). This works great for the first line of text that's left aligned, but it has some really strange results when working with NSTextAlignmentJustified or NSTextAlignmentCenter . It also doesn't calculate properly when the lines wrap around or (sometimes) if there are \n line breaks. I get stuff like this (this

Displaying Lots Of RichText : Choosing the best option

拜拜、爱过 提交于 2019-12-31 08:51:28
问题 What is the best way to display lots of RichText (HTML formatted) At the moment I'm working on an app for a forum. As you'd expect the posts on the site have lots of HTML formatting, lists, images bold text , colored text, etc... Now there are several options I can think of (non of them ideal, please if you think of any other options post them in the comments): Custom Cells using NSAttributedString+HTML + DTAttributedTextView for each post? Problems: I used the NSAttributedString+HTML

Super/Subscript appear to be broken in iOS13 (NSAttributedString)

十年热恋 提交于 2019-12-31 07:18:07
问题 Trying to display super/subscript text using NSAttributedString in a UITextView seems broken in iOS13 - unless anyone knows otherwise? Curiously if I use the UIFont systemFont then it works - but if I use any other font it doesn't. See below for my code to setup a UITextView in my test app. - (void)viewDidLoad { [super viewDidLoad]; UIFont* font = [UIFont systemFontOfSize:32]; //UIFont* font = [UIFont fontWithName:@"Helvetica Neue" size:32]; //UIFont* font = [UIFont fontWithName:@"Courier"

Get text range of link in UITextView

为君一笑 提交于 2019-12-31 03:26:48
问题 I have a UITextView that contains a link and some other text. The link detection is enabled and working (iOS8). However, I am at loss to find the range of the link within the textView. The idea is that the text is scanned (after link detection is done) and the link preloaded into a web view, so that when a user taps on an element somewhere, the web view can reveal itself. How can I get the range of the detected link within a UITextView? 回答1: A way to do it, is to use enumerateAttribute

NSAttributedString alignment not working on html content

谁说我不能喝 提交于 2019-12-30 09:06:08
问题 Want to change alignment of html label. Nothing works. I don't see any CSS in the HTML. There are no further settings changing the alignment. I also set left alignment directly on the UILabel. What am I missing? The code is in UILabel extension. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineBreakMode = NSLineBreakByWordWrapping; paragraphStyle.alignment = NSTextAlignmentLeft; NSDictionary *attr = @{NSDocumentTypeDocumentAttribute:

UILabel: Custom underline color?

喜夏-厌秋 提交于 2019-12-30 04:21:15
问题 I need the text of a UILabel to be black, but have a light gray underline under the text. Is this possible with NSAttributedString or TTTAttributedLabel ? Or is custom drawing using Core Graphics needed? CLARIFICATION: I need a specific color text on a different color underline. Example: blue text on red underline. 回答1: You can do with NSAttributedString as below. NSMutableAttributedString* string = [[NSMutableAttributedString alloc]initWithString:@"you string"]; [string addAttribute

UIPickerView won't allow changing font name and size via delegate's `attributedTitleForRow…`

爷,独闯天下 提交于 2019-12-30 02:37:06
问题 I use the following func to change the font color and font size, the color works but the font name and font size refuse to work. func pickerView(pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? var myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Arial-BoldMT", size: 45)!, NSForegroundColorAttributeName:UIColor.whiteColor()]) any help? Thx. 回答1: I have a another option may be it helpfull