开发者

Objective C: Simplest way of implementing multiple actions in a paragraph of text (like comments)

I have been trying to implement a comment engine in my app (UItableView) but have been facing challenges

1) How can I add the comment in the table cell with the format of "user name" 开发者_StackOverflow中文版+ "comment text" whereby the user can click on the username and the corresponding user profile will appear. The comment text will just be a static data in the cell

2) How can I dynamically calculate the height of all the comments which will eventually lead to the determination the entire cell height?

I see that Instagram's comment engine is what I have in mind (see below)

Objective C: Simplest way of implementing multiple actions in a paragraph of text (like comments)

Can anyone advise me on how I can implement the comment engine like Instagram? I have tried to subclass a UIControl and add a UILabel (as a property to it). But this approach seems a little confusing and inflexible. So any advise on this will be greatly appreciated.


If you comply to the MIT licence, you can use my OHAttributedLabel class.

This will allow you to use NSAttributedStrings with different styles for the words of the label (name in bold and blue, comment in black, for example) and add hyperlinks on the text too.

You can also use a properly configured instance (default font, size, etc) and its sizeThatFits: method to compute the size needed for the text and use the height of the returned size to compute your cell height accordingly.

[EDIT] As pointed by @Simon Lee, be warned that this uses CoreText, which is only available in iOS 3.2 for iPhone or iOS 4.0 on iPad.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜