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

4

1 に答える 1

0

UITextViewの問題の解決策ではありませんが、...私も同様の問題を抱えていたため、コアテキストにチャンスを与えることにしました。何が起こっているのかをより細かく制御できます。正規表現ステートメントを使用して文字列を属性付けし、リンク/電子メール/電話番号を表示し、さらに他のフォントを使用する機会を得ることができます。

于 2012-08-02T15:57:49.210 に答える