Get Width of last line of multiline UILabel

老子叫甜甜 提交于 2019-12-19 18:18:29

问题


I have a dynamic multi line UILabel and need to know the end of the text (X Coordinate) of the visible text (not the Label) so I can show something after the text. Is this possible?

thank you


回答1:


You'll be able to have more control over the text layout with the CoreText framework. Checkout the documentation:

There are also some nice open source things that already do a lot of the hard work for you, like: https://github.com/Cocoanetics/DTCoreText




回答2:


As far as I know , the best solution for this is to use a UIWebView instead of a UILabel. You just have to format the HTML for it to load and then add whatever you want to add after.

Example:

[webView loadHTMLString:[NSString stringWithFormat:@"<html><body><font face=\"arial\" size=\"2\">%@</font><font face=\"arial\" size=\"1\"> %@</font></body></html>",text1 , text2] baseURL:nil];

If you want to keep trying with UILabel / UITextView /any UIView for that matter , I only know of a way to figure out the height properly : [myView sizeToFit]; And then get it's frame.

Hope this helps.

Regards,

George



来源:https://stackoverflow.com/questions/11189600/get-width-of-last-line-of-multiline-uilabel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!