NSString이 있고 적절한 UILabel을 만들기 위해 높이를 알고 싶습니다. 이NSString 높이 가져 오기
NSString *string = @"this is an example";
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:10.0f]
forWidth:353.0
lineBreakMode:UILineBreakModeWordWrap];
float height = size.height;
높이를하는
는지금은 13.0이다. 나는이 문자열
NSString *string = @"this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example this is an example this is an example
this is an example ";
높이 (그건 불가능, 폭과 함께 353)는 항상 13.0이다 사용하는 경우 ... 무슨 내가 잘못 뭐하는 거지?
ADD : 그것은 lineBreakMode이 정확하지 않은 경우처럼, 그래서
size.width;
이 ... 잘 작동 ...하지만 그것은, 그렇지?
을한다. 개체가 아니라 방금 만든 CGSize. 그건 오타예요? –
하지만 'sizeWithFont : forWidth : lineBreakMode'는 NSString (예 : UILabel이 아닙니다)을 취합니다. – JAA
그것은 그것을 받아들이지 않습니다, 말하자면, 그것은 그것에 행동하고, 당신에게 크기를 돌려줍니다. 그러므로 'float height = string.height;'를'float height = size '로 변경하면된다.높이;', 나는 그것을 더 이해할 것 같아요. –