nslayoutmanager

UITextView contentSize changes and NSLayoutManager in iOS7

回眸只為那壹抹淺笑 提交于 2019-12-03 03:51:31
The problem: UITextView silently changes it's contentSize in some situations. The simplest case textView with large text and keyboard. Just add UITextView outlet and set - viewDidLoad as: - (void)viewDidLoad { [super viewDidLoad]; // expand default "Lorem..." _textView.text = [NSString stringWithFormat:@"1%@\n\n2%@\n\n3%@\n\n4%@\n\n5", _textView.text, _textView.text, _textView.text, _textView.text]; _textView.keyboardDismissMode = UIScrollViewKeyboardDismissModeInteractive; _textView.contentInset = UIEdgeInsetsMake(0, 0, 216, 0); } Now showing and hiding keyboard will cause text jumps in some

Animated UIImage in UITextView with TextKit

雨燕双飞 提交于 2019-11-30 17:21:13
I have a UIImage that contains multiple image frames and a duration which was sliced together from an animated GIF file. If I load the image in a UIWebView it will animate as expected, but I want to use a UITextView instead. The obvious choice is to use TextKit with a custom NSLayoutManger and many custom NSAttributedString attributes to achieve various drawing effects. I have a single UITextView that I'd like to give a NSAttributedString that contains NSTextAttachment s for all of the images I need to display inline. It's working fine except for when I load one of these animated UIImages ,

What is Causing this Unwanted Content Inset with UITextView in iOS 8 (not there in iOS 7)?

天大地大妈咪最大 提交于 2019-11-30 15:06:18
I've been creating UITextView s programatically, using auto layout, in iOS 7. Something like this: _textView = [UITextView new]; _textView.translatesAutoresizingMaskIntoConstraints = NO; _textView.font = [UIFont systemFontOfSize:18.0]; _textView.delegate = self; [self.view addSubview:_textView]; In addition to the other constraints I've created, I have this one for the bottom of the text view: _textViewBottomConstraint = [NSLayoutConstraint constraintWithItem:_textView attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self.bottomLayoutGuide attribute:NSLayoutAttributeTop

Animated UIImage in UITextView with TextKit

允我心安 提交于 2019-11-30 01:31:47
问题 I have a UIImage that contains multiple image frames and a duration which was sliced together from an animated GIF file. If I load the image in a UIWebView it will animate as expected, but I want to use a UITextView instead. The obvious choice is to use TextKit with a custom NSLayoutManger and many custom NSAttributedString attributes to achieve various drawing effects. I have a single UITextView that I'd like to give a NSAttributedString that contains NSTextAttachment s for all of the images

What is Causing this Unwanted Content Inset with UITextView in iOS 8 (not there in iOS 7)?

有些话、适合烂在心里 提交于 2019-11-29 21:47:12
问题 I've been creating UITextView s programatically, using auto layout, in iOS 7. Something like this: _textView = [UITextView new]; _textView.translatesAutoresizingMaskIntoConstraints = NO; _textView.font = [UIFont systemFontOfSize:18.0]; _textView.delegate = self; [self.view addSubview:_textView]; In addition to the other constraints I've created, I have this one for the bottom of the text view: _textViewBottomConstraint = [NSLayoutConstraint constraintWithItem:_textView attribute

Getting a glyph boundingRect in draw#rect in UILabel. Fat bounty

怎甘沉沦 提交于 2019-11-29 14:21:55
Using Swift, I want to get the boundingRect of a glyph, in draw#rect in a UILabel, the UILabel already has a size (say 300x300 in the example) and qualities such as the text being centered. class RNDLabel: UILabel { override func draw(_ rect: CGRect) { let manager = NSLayoutManager() let store = NSTextStorage(attributedString: NSAttributedString( string: text!, attributes: [NSAttributedString.Key.font: font])) store.addLayoutManager(manager) let textContainer = NSTextContainer(size: rect.size) // note, intrinsicContentSize is identical there, no difference manager.addTextContainer

Using a CALayer to highlight text in a UITextView which spans multiple lines

隐身守侯 提交于 2019-11-28 20:38:09
问题 This is a continuation of Getting CGRect for text in a UITextView for the purpose of highlighting with a CALayer. I'm having trouble with getting the correct rectangle for the ranges in each line fragment. NSString* searchString = @"Returns the range of characters that generated"; NSRange match = [[[self textView]text]rangeOfString:searchString]; NSRange matchingGlyphRange = [manager glyphRangeForCharacterRange:match actualCharacterRange:NULL]; [manager enumerateLineFragmentsForGlyphRange

Getting a glyph boundingRect in draw#rect in UILabel

北慕城南 提交于 2019-11-28 04:09:37
问题 Using Swift, I want to get the boundingRect of a glyph, in draw#rect in a UILabel. The UILabel already has a size (say 300x300 in the example) and qualities such as the text being centered. class RNDLabel: UILabel { override func draw(_ rect: CGRect) { let manager = NSLayoutManager() let store = NSTextStorage(attributedString: NSAttributedString( string: text!, attributes: [NSAttributedString.Key.font: font])) store.addLayoutManager(manager) let textContainer = NSTextContainer(size: rect.size

How does line spacing work in Core Text? (and why is it different from NSLayoutManager?)

和自甴很熟 提交于 2019-11-28 03:09:29
I'm trying to draw text using Core Text functions, with a line spacing that's as close as possible to what it would be if I used NSTextView. Take this font as an example: NSFont *font = [NSFont fontWithName:@"Times New Roman" size:96.0]; The line height of this font, if I would use it in an NSTextView is 111.0. NSLayoutManager *lm = [[NSLayoutManager alloc] init]; NSLog(@"%f", [lm defaultLineHeightForFont:font]); // this is 111.0 Now, if I do the same thing with Core Text, the result is 110.4 (assuming you can calculate the line height by adding the ascent, descent and leading). CTFontRef

Swift protocols: method does not override any method from its superclass

别等时光非礼了梦想. 提交于 2019-11-27 19:15:52
Since Xcode 6 still has a lots of bugs with Swift, I'm not sure is it one or I'm missing something. My class adopts protocol NSLayoutManagerDelegate. But it seems impossible to override method I need. I do as documentation describes: override func layoutManager(_ aLayoutManager: NSLayoutManager!, didCompleteLayoutForTextContainer aTextContainer: NSTextContainer!, atEnd flag: Bool) { } But I get error here: method does not override any method from its superclass. What should I do? You're implementing a method from the protocol, yes, but it's not an override. Just remove the override keyword. An