2011-01-11 17 views
7

मुझे लगता है कि मुझे आकार के लिए एक बढ़िया मामला मिला है: बाध्यकारी: जहां, रेटिना डिस्प्ले पर, कभी-कभी (यह शब्द रैपिंग पर आधारित लगता है) एक ऊंचाई 1 लाइन देता है वास्तव में इसकी तुलना में लंबा है, और वास्तव में यह वास्तव में आकर्षित करता है की तुलना में अधिक महत्वपूर्ण है।एनएसएसटींग आकारविथफॉन्ट: बाधित आकार: रेटिना डिस्प्ले पर गलत ऊंचाई लौटाना

नोट: वास्तविक कोड जो मैं उपयोग कर रहा हूं उसे प्रदर्शन केंद्र केंद्रित हाथ से परिवर्तनीय ऊंचाई तालिका दृश्य सेल कोड के अंदर दफनाया गया है, इसलिए मैंने इस मुद्दे को यथासंभव सरल नमूना कोड तक सीमित कर दिया है। (कृपया मेरे प्रश्न के अलावा किसी अन्य चीज का उत्तर देने का प्रयास करते समय ध्यान दें :-)

यह नमूना UIView इसकी सामग्री भरता है, फिट करने के लिए पाठ को मापता है (लपेटा जाता है), उस आय को भरता है, फिर पाठ खींचता है।

रेटिना डिवाइस (या सिम्युलेटर) पर ऊंचाई 1 लाइन बहुत अधिक लौटा दी जाती है, लेकिन प्री-रेटिना डिवाइस (या सिम्युलेटर) पर यह सही ऊंचाई देता है।

मैं किसी भी अंतर्दृष्टि की सराहना करता हूं, क्योंकि यह एक बग है जिसे मैं ठीक करना चाहता हूं!

बहुत धन्यवाद!

-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]; 
} 

पूरे सरल परियोजना उपलब्ध here है।

सिम्युलेटर चित्र:
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

+0

कठिन एक, सही भाग गया है? क्या कोई मदद कर सकता है? टम्बलवेड बैज कमाने के लिए बहुत मजेदार नहीं था! – eric

+2

अपना नमूना प्रोजेक्ट चलाने के बाद, मेरा मानना ​​है कि यह एक सिम्युलेटर या एसडीके की बग थी, हां, आईओएस 4.3 के साथ एक्सकोड 4 पर कोई समस्या नहीं है। – cxa

+0

धन्यवाद xan। यह अब काम कर रहा है क्योंकि यह वर्तमान एक्सकोड/आईओएस – eric

उत्तर

2

यह अपने सिम्युलेटर के साथ एक मुद्दा हो रहा है में ठीक काम करता है। यह मैं क्या हो गया, जब मैं इसे एक रेटिना सिम्युलेटर के साथ ओएस पर 4.3.2

enter image description here

+0

इसे देखने के लिए धन्यवाद। मुझे इसे आग लगाना होगा, और देखें कि यह अभी भी मौजूदा ओएस पर कर रहा है या नहीं। – eric

+1

आप सही हैं, यह नए ओएस/एक्सकोड में तय है। वास्तव में मेरे नमूना बनाम के लिए +1 बना रहा है। मुझे बताएं कि पाठ को मापने के लिए कैसे ;-) धन्यवाद Sum! – eric

+0

ठीक है .. मेरे पास आईओएस 8 में ही यही बग शो था ... इसे फिर से ध्यान देना शुरू करने का समय। इस बार यह डिवाइस पर हो रहा है !! – eric

1

के बाद विधि मैं गतिशील पाठ सामग्री के लिए लेबल की ऊंचाई को खोजने के लिए इस्तेमाल करते हैं। यह मेरा एप्लिकेशन

 
 
- (float)getHeightFortheDynamicLabel:(NSString *)stringForTheLabel 
{ 
    UITextView *aSampleTextView; 
    // 30 is the minimum height 
    aSampleTextView = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, mywidth, 30)]; 
    aSampleTextView.text = stringForTheLabel; 
    aSampleTextView.font = [UIFont systemFontOfSize:kMyFontSize]; 
    aSampleTextView.alpha = 0; 
    [self.view addSubview:aSampleTextView]; 
    float textViewHeight = aSampleTextView.contentSize.height; 
    [aSampleTextView removeFromSuperview]; 
    [aSampleTextView release]; 
    return textViewHeight;
}

+0

दिलचस्प विचार ... जैसा कि महंगा है ... मुझे एक नया रूप लेना होगा ... एक साल बाद ... :-) – eric

+0

इस विधि का उपयोग करने से पहले, मैंने अभी कोशिश की (CGSize theResultSize = [theString sizeWithFont : फॉन्ट बाध्य नहीं है: कंसस्ट्रेन]; ) लेकिन यह इतना सटीक नहीं था (मुझे नहीं पता क्यों)। भले ही यह विधि कम आदि स्मृति उपयोग का उपभोग करे, यह मेरे लिए ठीक काम करता है। –

0
 NSString *strSubstring = @"asdfghjklasdfghjkl adsds"; 

     CGFloat maxWidth = 205.0; 
     CGFloat maxHeight = 9999; 
     CGSize maximumLabelSize = CGSizeMake(maxWidth,maxHeight); 
     CGSize expectedLabelSize = [strSubstring sizeWithFont:[UIFont fontWithName:@"StagSans-Light" size:12] constrainedToSize:maximumLabelSize lineBreakMode:UILineBreakModeWordWrap]; 

     NSLog(@"returned a size h = %f, w = %f", expectedLabelSize.height, expectedLabelSize.width); 

     return expectedLabelSize; 
संबंधित मुद्दे