2017-03-24 5 views
8

छुपाता है यह मैं क्या लाइनों की अधिकतम संख्या निर्धारित करने के लिए कर रहा हूँ है:UITextView - अधिकतम लाइनों की स्थापना कर्सर

self.text_description.textContainer.maximumNumberOfLines = 2 
self.text_description.layoutManager.textContainerChangedGeometry(self.text_description.textContainer) 

जब 3 लाइन के बारे में शुरू करने के लिए, कर्सर गायब हो जाता है। इसे वापस रखने के लिए मुझे बैकस्पेस टैप करना होगा।

+0

कर्सर छुपाता है या यह कीबोर्ड के पीछे रहता है? – byJeevan

उत्तर

3

मानते हैं कि पाठ दृश्य में कर्सर कीबोर्ड के पीछे नहीं रहता है। मैंने एक सहायक विधि लिखी है जो टेक्स्ट के अंत में UITextField टेक्स्ट स्क्रॉल बनाती है।

- (void)scrollToCaretInTextView:(UITextView *)textView animated:(BOOL)animated 
{ 
    CGRect rect = [textView caretRectForPosition:textView.selectedTextRange.end]; //Get the content size of textview 
    rect.size.height += textView.textContainerInset.bottom; 
    [textView scrollRectToVisible:rect animated:animated]; 
} 
2

मुझे पूरा यकीन नहीं है कि आप क्या उम्मीद कर रहे हैं। यदि आप दो लाइनों को अधिकतम चाहते हैं, तो कोई तीसरी पंक्ति नहीं होनी चाहिए।

इस का उपयोग करें:

self.text_description.textContainer.maximumNumberOfLines = 2 
self.text_description.textContainer.lineBreakMode = .byTruncatingTail 

Limit the number of lines for UITextview

ऐसा लगता है क्या आप वास्तव में चाहते हैं दो पंक्तियों ऊंचाई के साथ एक TextView है? यदि यह सत्य है, तो आप इसे नियंत्रक को देखने का प्रयास करें।

self.text_description = UITextView(frame: CGRect(x: 100.0, y: 100.0, width: 200.0, height: 28.0)) 
self.text_description.backgroundColor = #colorLiteral(red: 0.8039215803, green: 0.8039215803, blue: 0.8039215803, alpha: 1) 
self.view.addSubview(self.text_description)