問題描述
我試圖在一行中的 UILabel 中顯示一大段文本.UILabel 是 UIScrollView 的子視圖,因此我可以滾動查看整個 UILabel.
I'm trying to show a long chunk of text inside a UILabel in one line. The UILabel is a subview of UIScrollView so I can scroll and see the entire UILabel.
我的問題是 sizeToFit 方法僅部分有效.
My problem is that the sizeToFit method only partialy works.
textLabel.attributedText = attributedString;
textLabel.numberOfLines = 1;
[textLabel sizeToFit];
textScrollView.contentSize = CGSizeMake(textLabel.frame.size.width, textLabel.frame.size.height);
UIScrollView 內(nèi)容大小變得足夠大,可以顯示整個 UILable,但是對于這樣的一行:
The UIScrollView content size gets big enough to show the entire UILable, but for a line like:
所以我會嘗試每隔一段時間在這里分享一些."
so i'll try to share some of them here every once in a while."
UILabel 顯示:
The UILabel shows:
所以我會嘗試分享一些...
so i'll try to share som...
我做錯了什么?
推薦答案
結(jié)果代碼很好 - 但是選中了使用自動布局.取消選中它 - 一切都很好......
Turns out the code is just fine - but the Use Autolayout was checked. Unchecked it - everything works just great...
這篇關(guān)于UILabel sizeToFit 方法無法正常工作的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!