Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialChristopher Santos
Courses Plus Student 10,697 PointsTrouble filling out the whole body text field
My Body Label text field is only displaying one line of text. I'm not sure if when you input text if it matters if you input a newline into the text. Or if it's supposed to just automatically word wrap your input. I have this in my EntryCell.m
-
(CGFloat)heightForEntry:(DiaryEntry *)entry { const CGFloat topMargin = 35.0f; const CGFloat bottomMargin = 80.0f; const CGFloat minHeight = 106.0f;
UIFont *font = [UIFont systemFontOfSize:[UIFont systemFontSize]];
CGRect boundingBox = [entry.body boundingRectWithSize:CGSizeMake(202, CGFLOAT_MAX) options:(NSStringDrawingUsesFontLeading | NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName: font} context:nil];
return MAX(minHeight, CGRectGetHeight(boundingBox) + topMargin + bottomMargin); }
1 Answer
Marshall Huss
3,504 PointsUITextField
can only handle a single line of text. You'll want to look at using a UITextView instead.
Forrest Wilson
21,862 PointsForrest Wilson
21,862 PointsWhere do you change the UITextField to UITextView?
Marshall Huss
3,504 PointsMarshall Huss
3,504 PointsIf you're using Interface Builder then you'll need to delete the
UITextField
, drag in aUITextView
, and hook up the outlet to a@property
. If you're doing it in code just swap out the class type and initialize the correct object type.Forrest Wilson
21,862 PointsForrest Wilson
21,862 PointsOh right, got it! Thanks Marshall!
Marshall Huss
3,504 PointsMarshall Huss
3,504 Points