Translate

顯示具有 UILabel 標籤的文章。 顯示所有文章
顯示具有 UILabel 標籤的文章。 顯示所有文章

2015年3月30日 星期一

UILabel and UITextView

最近遇到一個問題
字串相同字型大小相同
在UILabel跟UITextView呈現的size不一樣
後來在這邊找到了解答


textView.textContainer.lineFragmentPadding = 0; textView.textContainerInset = UIEdgeInsetsZero; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = -0.38; NSDictionary *attrsDictionary = @{ NSFontAttributeName: [UIFont fontWithName:@"HelveticaNeue" size:13.0f], NSParagraphStyleAttributeName: paragraphStyle}; textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attrsDictionary];

2013年1月9日 星期三

UILabel auto size

我找過很多資料
發現大部份都是用比較複雜的方法去取得text的長度
再去幫UILabel從新設定尺寸大小
但是其實只需要關鍵的兩行代碼
就可以完成那些複雜的算式

UILabel *temp_lab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 40, 20)];
[temp_lab setText:@"ddddddddddddddddddddddddddddddddddddddddddddddddddd"];

//重點
[temp_lab setNumberOfLines:0];
[temp_lab sizeToFit];