Placement/Positioning/Alignment of UIScrollView w.r.t. length of Title NSString
Posted
by Shoaibi
on Stack Overflow
See other posts from Stack Overflow
or by Shoaibi
Published on 2010-04-12T17:55:04Z
Indexed on
2010/04/13
2:13 UTC
Read the original article
Hit count: 362
I have a scenario where i show stuff like:
-----------------------------------
titleview (UITextView)
______________
tArea (UIScrollView)
ttextview (UITextView)
-----------------------------------
Now here is the condition:
- Length of titleview's text is dynamic, varies based on user input.
Because of the condition I have trouble placing tArea e.g. UIScrollView on the screen, it either appears way too below than the titleview, or overlaps it.
Previously what i did:
- Count the number of characters in titleview.text.length and divide them by 27 (e.g. characters in one line when using boldSystemFontOfSize:20) and multiply by 10 to get the starting X of tArea e.g. UIScrollView.
But that sucked. Because i had to duplicate code for rotation to landscape.
What do i have now? :
CGSize titlesize = [title sizeWithFont:[UIFont systemFontOfSize:20]
constrainedToSize:CGSizeMake(5, 90)
lineBreakMode:UILineBreakModeWordWrap];
ttitleview = [[UITextView alloc] initWithFrame:CGRectMake(5, 5, 310,titlesize.height)];
ttitleview.text = title;
ttitleview.font = [UIFont boldSystemFontOfSize:20];
ttitleview.backgroundColor = [UIColor clearColor];
ttitleview.editable = NO;
[self.view addSubview:ttitleview];
CGSize textsize = [ttext sizeWithFont:[UIFont systemFontOfSize:20]
constrainedToSize:CGSizeMake(5, 350)
lineBreakMode:UILineBreakModeWordWrap];
tArea = [[UIScrollView alloc] initWithFrame:CGRectMake(5, titlesize.height, 310, 230)];
tArea.contentSize = CGSizeMake(310, textsize.height+20);
tArea.pagingEnabled = FALSE;
tArea.scrollEnabled = TRUE;
tArea.backgroundColor = [UIColor clearColor];
[self.view addSubview:tArea];
ttextview = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 310, textsize.height + 20)];
ttextview.text = ttext;
ttextview.font = [UIFont systemFontOfSize:20];
ttextview.backgroundColor = [UIColor clearColor];
ttextview.editable = NO;
[tArea addSubview:ttextview];
But its no use. Looking for an elegant solution than this.
© Stack Overflow or respective owner