Boyut için bir kenar durumu buldum düşünüyorumWithFont: constrainedToSize: Burada, retina ekranında, bazen (sözcük kaydırma temelli) bir yükseklik 1 satırı döndürür aslında daha büyüktür, ve daha önemlisi aslında çizer.NSString sizeWithFont: constrainedToSize: retina ekranlarında yanlış yükseklik geri dönüyor
NOT: Kullandığım gerçek kod, performans merkezli elle çizilmiş değişken yükseklikli tablo görünümü hücre kodunun içine gömüldü, bu yüzden sorunu olabildiğince basit bir örnek kodla ayırdım. (Lütfen bu soruya başka bir soruya cevap vermeye çalıştığınızda dikkat edin :-)
Bu örnekte UIView içeriği doldurur, metni sığdırır (sarılır), bu dolguyu doldurur, sonra metni çizer.
Bir retina aygıtında (veya simülatörde) yükseklik 1 satır çok uzun, ancak bir retina öncesi aygıtta (veya simülatörde) döndürülürse, doğru yüksekliği döndürür.
Düzeltmek istediğim bir hata olduğundan, herkesin sahip olabileceği herhangi bir kavrayışı takdir ediyorum!
Çok teşekkürler!
-Eric
- (void)drawRect:(CGRect)rect {
NSString * theString = @"Lorem ipsum dolor sit ameyyet, consectetur adipiscing elit. Etiam vel justo leo. Curabitur porta, elit vel.";
UIFont * theFont = [UIFont systemFontOfSize:12];
CGSize theConstraint = CGSizeMake(rect.size.width - 20, rect.size.height - 20);
CGSize theResultSize = [theString sizeWithFont:theFont constrainedToSize:theConstraint];
// dump the measurements
NSLog(@"returned a size h = %f, w = %f", theResultSize.height, theResultSize.width);
// fill the whole rect
CGContextRef context = UIGraphicsGetCurrentContext();
[[UIColor yellowColor] set];
CGContextFillRect(context, rect);
// fill the measured rect
CGRect theRect = CGRectMake(10, 10, theResultSize.width, theResultSize.height);
context = UIGraphicsGetCurrentContext();
[[UIColor cyanColor] set];
CGContextFillRect(context, theRect);
// draw the text
[[UIColor blackColor] set];
[theString drawInRect:theRect withFont:theFont];
}
bütün basit proje here mevcuttur.
Simülatörü Görüntüler:
http://files.droplr.com/files/9979822/aLDJ.Screen%20shot%202011-01-11%20at%2012%3A34%3A34.png http://files.droplr.com/files/9979822/YpCM.Screen%20shot%202011-01-11%20at%2012%3A36%3A47.png
Zor bir o bitince ne var? Birisi yardım edebilir mi? Tumbleweed rozeti kazanmak için süper eğlenceli değildi! – eric
Örnek projenizi yürüttükten sonra, bunun bir simülatör veya SDK'nın hatası olduğuna inanıyorum, evet, Xcode 4'te iOS 4.3 ile ilgili bir sorunu yok. – cxa
Teşekkürler xan. Şu anki Xcode/iOS – eric