Created
April 10, 2012 16:11
-
-
Save mrjjwright/2352504 to your computer and use it in GitHub Desktop.
Modify TUIKit example to show textview inside of a scrollview
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
/* TUINSView is the bridge between the standard AppKit NSView-based heirarchy and the TUIView-based heirarchy */ | |
TUINSView *tuiScrollViewContainer = [[TUINSView alloc] initWithFrame:b]; | |
[scrollViewWindow setContentView:tuiScrollViewContainer]; | |
scrollExample = [[TUIScrollView alloc] initWithFrame:b]; | |
scrollExample.backgroundColor = [TUIColor redColor]; | |
TUITextView *textView = [[TUITextView alloc] initWithFrame:scrollExample.bounds]; | |
textView.text = @"hellodfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfddfdfd"; | |
textView.autoresizingMask = TUIViewAutoresizingFlexibleWidth; | |
textView.delegate = self; | |
scrollExample.horizontalScrollIndicatorVisibility = TUIScrollViewIndicatorVisibleNever; | |
scrollExample.scrollEnabled = YES; | |
scrollExample.clipsToBounds = YES; | |
[scrollExample setContentSize:textView.bounds.size]; | |
[scrollExample addSubview:textView]; | |
tuiScrollViewContainer.rootView = scrollExample; | |
[self showScrollViewExampleWindow:nil]; | |
} | |
- (void)textViewDidChange:(TUITextView *)textView { | |
CGFloat heightOfText = textView.heightOfText; | |
CGRect f = textView.frame; | |
f.size.height = heightOfText; | |
textView.frame = f; | |
[scrollExample setContentSize:f.size]; | |
} |
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
//Add this to TUITextView | |
-(CGFloat) heightOfText { | |
CGFloat height = [renderer sizeConstrainedToWidth:self.bounds.size.width].height; | |
return height; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Quick Q: This doesn't work when the line height is 1. Any fix?