1

Project

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.

Problem

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.

Question

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?

enter image description here

Community
  • 1
  • 1
Jason McCreary
  • 71,546
  • 23
  • 135
  • 174

1 Answers1

0

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.

Bernd Rabe
  • 790
  • 6
  • 23
  • Core Text is a technology for text layout and font processing. Have a look in the "Core Text Programming Guide". – Bernd Rabe Aug 03 '12 at 07:16
  • Basis is an NSAttributedString - a string where attributes are assigned to parts of the string as font/font size/color etc. You can find several sample projects in Xcode's documentation as well as on Github (e.g. akosma / CoreTextWrapper; jonasschnelli / I7CoreTextExample). – Bernd Rabe Aug 03 '12 at 07:25