Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic UITextView size based on content in Swift

I don't suppose someone could guide me on the proper way to dynamically size a UITextView while still using Auto-Layout? Using Swift, that is.

I've tried programmatically adjusting the bottom constraints in attempt to get the UITextView to hug the content. But I'm not sure how to get the height of the content of the UITextView?

I'm attempting to load data into UITextView fields, then, dynamically adjust them to look neat.

@IBOutlet weak var serviceDescriptionTextViewBottomGuide: NSLayoutConstraint! 

override func viewDidLoad() {

        self.activityName.text = serviceCodes[selectionValue]
        self.serviceDescriptionTextView.text = serviceDescription[selectionValue]
        self.whenToUseDescriptionTextView.text = whenToUseCode[selectionValue]

        self.serviceDescriptionTextViewBottomGuide?.constant += x
    }

enter image description here

like image 541
C. Thomas Brittain Avatar asked Apr 02 '15 00:04

C. Thomas Brittain


1 Answers

Disable scrolling and do not put any other constraint that can dictate the height of UITextView.

like image 136
Abdullah Avatar answered Sep 28 '22 08:09

Abdullah