Skip to content

Instantly share code, notes, and snippets.

@nocchijiang
Last active July 19, 2019 07:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nocchijiang/c8e3429890f4f031752c82ac3a35835a to your computer and use it in GitHub Desktop.
Save nocchijiang/c8e3429890f4f031752c82ac3a35835a to your computer and use it in GitHub Desktop.
Sample Code for Reproducing Infinite Recursion changing frame during setContentSize: for UITextView
#import "ViewController.h"
@interface TextView : UITextView
@end
@implementation TextView
- (void)setContentSize:(CGSize)contentSize {
CGRect frame = self.frame;
frame.size.height = contentSize.height + 5;
self.frame = frame;
[super setContentSize:contentSize];
}
@end
@interface ViewController ()
@end
@implementation ViewController {
UITextView *_textView;
}
- (void)loadView {
[super loadView];
CGRect rootFrame = self.view.frame;
TextView *textView = [[TextView alloc] initWithFrame:CGRectMake(0, 88, CGRectGetWidth(rootFrame), 40)];
textView.textColor = UIColor.blackColor;
textView.layer.borderColor = UIColor.blackColor.CGColor;
textView.layer.borderWidth = 1;
[self.view addSubview:textView];
_textView = textView;
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, CGRectGetHeight(rootFrame) - 200, CGRectGetWidth(rootFrame), 60)];
[button setTitleColor:UIColor.blackColor forState:UIControlStateNormal];
[button setTitle:@"hit me!!!" forState:UIControlStateNormal];
[button addTarget:self action:@selector(tap) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
- (void)tap {
_textView.text = [NSString stringWithFormat:@"%@%@", _textView.text, @"more text!!!!"];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment