Last active
July 19, 2019 07:19
-
-
Save nocchijiang/c8e3429890f4f031752c82ac3a35835a to your computer and use it in GitHub Desktop.
Sample Code for Reproducing Infinite Recursion changing frame during setContentSize: for UITextView
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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