Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Modify TUIKit example to show textview inside of a scrollview
/* 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];
}
//Add this to TUITextView
-(CGFloat) heightOfText {
CGFloat height = [renderer sizeConstrainedToWidth:self.bounds.size.width].height;
return height;
}
@avaidyam

This comment has been minimized.

Copy link

@avaidyam avaidyam commented May 8, 2012

Quick Q: This doesn't work when the line height is 1. Any fix?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment