textkit

How do I locate the CGRect for a substring of text in a UILabel?

守給你的承諾、 提交于 2019-11-26 12:06:10
For a given NSRange , I'd like to find a CGRect in a UILabel that corresponds to the glyphs of that NSRange . For example, I'd like to find the CGRect that contains the word "dog" in the sentence "The quick brown fox jumps over the lazy dog." The trick is, the UILabel has multiple lines, and the text is really attributedText , so it's a bit tough to find the exact position of the string. The method that I'd like to write on my UILabel subclass would look something like this: - (CGRect)rectForSubstringWithRange:(NSRange)range; Details, for those who are interested: My goal with this is to be

How to embed small icon in UILabel

老子叫甜甜 提交于 2019-11-26 04:04:30
问题 I need to embed small icons ( sort of custom bullets ) to my UILabel in iOS7. How can I do this in interface designer? Or at least in code? In Android there are leftDrawable and rightDrawable for labels, but how it is done in iOS? Sample in android : 回答1: You can do this with iOS 7's text attachments, which are part of TextKit. Some sample code: NSTextAttachment *attachment = [[NSTextAttachment alloc] init]; attachment.image = [UIImage imageNamed:@"MyIcon.png"]; NSAttributedString

How do I locate the CGRect for a substring of text in a UILabel?

家住魔仙堡 提交于 2019-11-26 02:51:05
问题 For a given NSRange , I\'d like to find a CGRect in a UILabel that corresponds to the glyphs of that NSRange . For example, I\'d like to find the CGRect that contains the word \"dog\" in the sentence \"The quick brown fox jumps over the lazy dog.\" The trick is, the UILabel has multiple lines, and the text is really attributedText , so it\'s a bit tough to find the exact position of the string. The method that I\'d like to write on my UILabel subclass would look something like this: - (CGRect

iOS 7 TextKit - How to insert images inline with text?

陌路散爱 提交于 2019-11-26 02:04:39
问题 I am trying to get the following effect using a UITextView: Basically I want to insert an image between text. The image can simply just take up 1 row of space so there is no wrapping necessary. I tried just adding a UIView to the subview: UIView *pictureView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 25, 25)]; [pictureView setBackgroundColor:[UIColor redColor]]; [self.textView addSubview:pictureView]; But it seems to float over the text and cover it. I did a bit of reading on exclusion

Detecting taps on attributed text in a UITextView in iOS

老子叫甜甜 提交于 2019-11-26 00:50:08
问题 I have a UITextView which displays an NSAttributedString . This string contains words that I\'d like to make tappable, such that when they are tapped I get called back so that I can perform an action. I realise that UITextView can detect taps on a URL and call back my delegate, but these aren\'t URLs. It seems to me that with iOS 7 and the power of TextKit this should now be possible, however I can\'t find any examples and I\'m not sure where to start. I understand that it\'s now possible to