Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 01-27-2010, 11:45 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2009
Posts: 5
Default Autoresize UITextView and UIScrollView

Hello guys,

I already did several searches on the Forum and Google, but I couldn't find a solution to my problem.

I have a Detail View for a product that includes a UIScrollView and a few subviews (UIImageView, UILabel, UITextView). You can find an example here.

First I wanna autoresize the UITextView (not the text itself!) to the corresponding height. Then I wanna autoresize the entire UIScrollView so that it fits the height of my UITextView and the elements above it. I've tried the following code:

Code:
myUITextView.frame = CGRectMake(2.0, 98.0, 316.0, self.view.bounds.size.height);

[scrollView setContentOffset:CGPointMake(0.0, 0.0) animated:NO];
scrollView.contentSize = CGSizeMake(320.0, 98.0 + [myUITextView frame].size.height);

[self.view addSubview:scrollView];
*98.0 + [myUITextView frame].size.height)* because my thought was: After getting the height of myUITextView, add the height of the other subviews (98.0) to it.

Unfortunately it doesn't work very well. Depending on the content of the UIScrollView, it is too short or too long. I did some logging with the result that the height of the UITextView is always the same:

Quote:
> 2010-01-27 14:15:45.096 myApp[1362:207] [myUITextView frame].size.height: 367.000000
Thanks!
dennis3484 is offline   Reply With Quote
Old 06-04-2010, 02:36 PM   #2 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: NYC
Posts: 37
Default

did you ever figure this one out?
beleg_1998 is offline   Reply With Quote
Old 06-04-2010, 04:49 PM   #3 (permalink)
Registered Member
 
azdev's Avatar
 
Join Date: Oct 2009
Posts: 104
Default

Since your UIScrollView is doing the scrolling and not the UITextView, myUITextView can't have a fixed height.

Use:
Code:
myUITextView.text = someString;
CGRect frame = myUITextView.frame;
frame.size.height = myUITextView.contentSize.height;
myUITextView.frame = frame;
__________________
My apps
Wordmaster
Wordmaster Free
LOLCreator
loltranslate
azdev is offline   Reply With Quote
Old 06-07-2010, 11:36 AM   #4 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: NYC
Posts: 37
Default

What I did was create a delegate from the table to the view controller that controls the size of the scrollview. Then when the table is done rendering, I call a delegate function to update the size of the scroolview. It works perfectly except for one thing. I am not sure how to calculate the size of the table to send to this delegate. I tried self.view.bounds.size.height but I keep getting null. Right now I am just sending it a test number. It works, but I don’t want to leave this hardcoded. Did you run into this problem. I will post my solution if I ever figure it out. Thanks.
beleg_1998 is offline   Reply With Quote
Old 06-07-2010, 12:20 PM   #5 (permalink)
Registered Member
 
Join Date: Jan 2010
Location: NYC
Posts: 37
Default

Quote:
Originally Posted by beleg_1998 View Post
What I did was create a delegate from the table to the view controller that controls the size of the scrollview. Then when the table is done rendering, I call a delegate function to update the size of the scroolview. It works perfectly except for one thing. I am not sure how to calculate the size of the table to send to this delegate. I tried self.view.bounds.size.height but I keep getting null. Right now I am just sending it a test number. It works, but I don’t want to leave this hardcoded. Did you run into this problem. I will post my solution if I ever figure it out. Thanks.

I was doing this:

NSLog(@"This is the height of the view: %@", self.tableView.frame.size.height);

I was always getting null was because I was not taking into account that the height is a float, like so:


CGFloat viewHeight = self.tableView.frame.size.height;
NSLog(@"This is the height of the view: %f", viewHeight);

thanks
beleg_1998 is offline   Reply With Quote
Reply

Bookmarks

Tags
autoresize, iphone, uiscrollview, uitextview

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 351
17 members and 334 guests
ADY, Dani77, Duncan C, Grinarn, HemiMG, Herbie, JasonR, linkmx, macquitzon216, mer10, Monstertaco, prchn4christ, Robiwan, sly24, Touchmint, twerner, zulfishah
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,881
Threads: 89,228
Posts: 380,760
Top Poster: BrianSlick (7,129)
Welcome to our newest member, macquitzon216
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 01:39 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0