मैंने सुझाए गए समाधान के साथ मेरी समस्या का विवरण के साथ "Sizing a UILabel (in the iPhone SDK) to fit?" अपना प्रश्न अपडेट किया है, लेकिन मुझे जवाब नहीं मिला। शायद मैं एक नया सवाल पूछकर बेहतर परिणाम होगा ...मैं कैसे प्राप्त करूं - [एनएसएसटींग आकार WithFont: forWidth: lineBreakMode:] काम करने के लिए?
मैं निम्नलिखित कोड के बाद एक ब्रेकपाइंट सेट:
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. यही कारण है कि इसे और अधिक की तरह लगता है है।
मेरे पास एक ही परिणाम था: 21. किसी को पता है कि वह संख्या कहां से आती है, या यह सिर्फ उस फ़ॉन्ट आकार के आधार पर है। मूर्ख विधि। – ZaBlanc
यदि आप UITextView का उपयोग कर रहे हैं, तो मेरा जवाब यहां देखें: http://stackoverflow.com/questions/2330939/sizewithfont-doesnt-give-correct-height-for-uitextview-if-there-is-a -लॉन्ग-स्ट्रिन/15408198 # 15408198 – domsom