Я обновил свой вопрос «Определение размера UILabel (в iPhone SDK) подходит? "с описанием моей проблемы с предложенным решением, но не получил ответа. Возможно, у меня будут лучшие результаты, если я задам новый вопрос ...
Я установил точку останова после следующего кода:
NSString *theText = @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
CGSize theSize = [theText sizeWithFont:[UIFont systemFontOfSize:17.0f] forWidth:260.0 lineBreakMode:UILineBreakModeWordWrap];
theSize.height
21 и theSize.width
231. Что я делаю не так? Эта высота не может быть ни в пикселях, ни в количестве строк.
Обратите внимание, что [UIFont systemFontOfSize:17.0f]
предназначен для указания шрифта по умолчанию.
Обновление: я изменил код на:
CGSize constraintSize;
constraintSize.width = 260.0f;
constraintSize.height = MAXFLOAT;
NSString *theText = @"When in the Course of human events, it becomes necessary for one people to dissolve the political bands which have connected them with another, and to assume among the powers of the earth, the separate and equal station to which the Laws of Nature and of Nature's God entitle them, a decent respect to the opinions of mankind requires that they should declare the causes which impel them to the separation.";
CGSize theSize = [theText sizeWithFont:[UIFont systemFontOfSize:17.0f] constrainedToSize:constraintSize lineBreakMode:UILineBreakModeWordWrap];
theSize.height
- 273. Это больше похоже на это.