NSString'im var ve uygun bir UILabel oluşturmak için yüksekliğini bilmek istiyorum. BuNSString yüksekliğini edinin
NSString *string = @"this is an example";
CGSize size = [string sizeWithFont:[UIFont systemFontOfSize:10.0f]
forWidth:353.0
lineBreakMode:UILineBreakModeWordWrap];
float height = size.height;
yüksekliği yapmak
şimdi 13.0 olduğunu. Bu dize
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 ";
yüksekliği (bu imkansız, genişliği olarak ve birlikte 353) her zaman 13.0 olduğunu kullanırsanız ... ne yanlış yapıyorum?
ADD: Bu lineBreakMode doğru değilse gibi öyle çok
size.width;
... iyi çalışıyor ... ama buna değil mi?
hangi. Nesne, yeni oluşturduğunuz CGSize değil. Bu bir yazım hatası mı? –
ancak "sizeWithFont: forWidth: lineBreakMode" bir NSString'i (örneğin bir UILabel değil) alır ... bu yüzden doğru mu ... değil mi? – JAA
Bunu almaz, söyler, üzerinde hareket eder ve size bir boyut verir. Yani eğer float yüksekliğini = string.height; 'float height = size değiştirecekseniz.yükseklik; ', sanırım daha mantıklı olacak. –