Hi NGUI Team,
I am planning to implement a Facebook application in which the user can see his wall posts,the snapshot for the Post Prefab is attached, now the problem which i am facing is that i want to add a ShowMore button(as shown in the image) which will appear in case the message for the post(UILabel) is more then lets say 4 lines(which has a fixed Max width of lets say 200 pixels).
Now on pressing the Show more button i want the complete post message to appear, to do that i will have to increase the background sprite of the prefab to certain pixels(depending on total number of lines for a post) plus i will even have to shift down the elements(like comment button , share button and like button)which are placed lower than the message to same number of pixels.But i am not able to understand how can i get the total line count for the UILabel when it is showing the complete messages.if i can have the line count i can easily convert it to pixels and do my stuff.
Now here are the things which i have already tried,
i tried creating a custom method which could help me get total number of lines, here is the code for that
public static int GetTotalLines(UILabel label)
{
Vector2 result = label.font.CalculatePrintedSize(label.text,false,UIFont.SymbolStyle.None);
int totalLInes = Mathf.RoundToInt((result.x * label.transform.localScale.x)/label.lineWidth);
return totalLInes;
}
now the issue with this functionality is that the font.CalculatePrintedSize doesn't calculate pixel space for the white spaces in the message, so if a message has lot of white spaces it will lead to wrong result.
i even tried out the relativeSize property of the UILabel as described in this link
http://www.tasharen.com/forum/index.php?topic=4509.0but even this will not work for me as it returns the position with respect to max line count set, not total size(i.e not size in show more mode)
Is there any other way which you guys could guide me through.
Thanks in Advance.