Reputation: 396
Okay I'm not really sure how to explain this. But here goes. I have a UITextView with content that is dynamically populated. I have worked out how to resize automatically depending on the amount of text within it. It could be one line it could be 10.
Now I have a UIView that I have customised which has a rounded Rect code below.
The .h file
@interface roundedEdges : UIView
{
}
The .m file
- (void) drawRect:(CGRect)rect
{
CGRect frame = self.bounds;
UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:frame cornerRadius:8.0];
[[UIColor whiteColor] setFill];
[path fill];
}
What I would like to do is make the rounded UIView to be constrained to the height of the UITextView. Currently the UITextView is sitting on top of the UIView. This way it provides a rounded box effect.
IS there a way to resize the above code (UIView) to be constrained depending on how much text is coming into the UITextView?
If so how?
Thanks in advance! Jeremy
Upvotes: 1
Views: 544
Reputation: 6342
To dynamic change in height or width of textView or label depends upon the text size this code is working fine........
I have used this code for both UITextView and UILabel
CGFloat heightTXT = [[txtView text] sizeWithFont:txtView.font constrainedToSize:CGSizeMake(txtView.frame.size.width,INFINITY) lineBreakMode:UILineBreakModeWordWrap].height;
[txtView setFrame:CGRectMake(txtView.frame.origin.x,txtView.frame.origin.y,txtView.frame.size.width,heightTXT];
Upvotes: 0