UILabel text size height
UILabel 텍스트 사이즈 높이를 가져와 볼까요.
UILabel에 들어갈 텍스트를 파싱이나 로컬 데이터로 받아와 화면에 모두 노출시킬 때 사용합니다.
UITextView도 가능합니다만 저는 웬만하면 UILabel로 처리를 합니다.
setNumberOfLine을 0으로 주면 얼마든지 출력을 할 수 있어요.
소스코드
UILabel * bodyText;
-(float)expectedHeight{
[bodyText setNumberOfLines:0];
[bodyText setLineBreakMode:NSLineBreakByCharWrapping];
UIFont *font = [UIFont systemFontOfSize:14.0];
NSDictionary *attributesDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
font, NSFontAttributeName,
nil];
CGSize maximumLabelSize = CGSizeMake(bodyText.frame.size.width,9999);
CGRect expectedLabelRect = [[bodyText text] boundingRectWithSize:maximumLabelSize
options:(NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading)
attributes:attributesDictionary
context:nil];
CGSize *expectedLabelSize = &expectedLabelRect.size;
return expectedLabelSize->height;
}
'IT > iOS' 카테고리의 다른 글
UICollectionview cell selection (0) | 2014.09.15 |
---|---|
[iOS] Draw line (0) | 2014.08.13 |
[iOS] 원 이미지 만들기 (0) | 2014.08.12 |
UIButton title multi-line (0) | 2014.08.08 |
프로젝트 개발과정 (0) | 2014.08.05 |
문자열에서 숫자만 추출하기 (0) | 2014.08.04 |
json 데이터에서 key, object 추출하기 (0) | 2014.08.01 |
NSMutableArray shuffle (배열 랜덤으로 섞기) (0) | 2014.07.23 |