I am attempting to replicate the native iMessage app. I have used AcaniChat as a foundation.
I wanted automatic highlighting , so I modified the code to use UITextView
instead of UILabel
. I realize there are options such as FancyLabel and Three20 . However, UITextView
does this natively.
I am having a difficult time getting the padding/size of UITextView
right. I updated the contentInset
property based on suggestions in other answers .
msgText.contentInset = UIEdgeInsetsMake(-11.0f, -8.0f, 0.0f, -8.0f);
I am also determining the size with the following:
CGSize size = [[(Message *)object text] sizeWithFont:[UIFont systemFontOfSize:kMessageFontSize]
constrainedToSize:CGSizeMake(kMessageTextWidth, CGFLOAT_MAX)
lineBreakMode:UILineBreakModeWordWrap];
Nonetheless, some text is still being cut off (see image below). Notably the phone number and email address (right) as well as the "that cut off?" (left)
I have verified this is not due to the dataDetectorsTypes
property.
I can solve this by increasing the CGRect
of the UITextView
. But I want to better understand the affects of margin/padding and size of the UITextView
. I don't want to arbitrarily increase the size by 20.0f
to make it work .
As such, what is the code or combination of code that I can reliably set the size of the message bubble?
Not a solution for your problems with UITextView but ... I had similar problems and decided to give core text a chance. You have simply more control about what is happening. You could have your string attributed using regex statements to make links/emails/phone numbers visible and have furthermore the chance to use even other fonts.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.