Friday, 6 January 2017

UITextViewDelegate Property in Swift

UITextViewDelegate Property in Swift



* Swift 2 + :- 



// Make current ViewController respond to UITextViewDelegate events
myTextView.delegate = self

// Update UITextView content
myTextView.text = "In this video we are going to edit UITextView from our Swift code. www.swiftdeveloperblog.com"

// Change UITextView background colour
myTextView.backgroundColor = UIColor.yellowColor()

// User RGB colour
myTextView.backgroundColor = UIColor(red: 39/255, green: 53/255, blue: 182/255, alpha: 1)

// Update UITextView font size and colour
myTextView.font = UIFont.systemFontOfSize(20)
myTextView.textColor = UIColor.whiteColor()

myTextView.font = UIFont.boldSystemFontOfSize(20)
myTextView.font = UIFont(name: "Verdana", size: 17)

// Make UITextView Editable
myTextView.editable = true

// Capitalize all characters user types
myTextView.autocapitalizationType = UITextAutocapitalizationType.AllCharacters

// Make web links clickable
myTextView.selectable = true
myTextView.editable = false
myTextView.dataDetectorTypes = UIDataDetectorTypes.Link

// Make UITextView corners rounded
myTextView.layer.cornerRadius = 10

// Enable auto-correction and Spellcheck
myTextView.autocorrectionType = UITextAutocorrectionType.Yes
myTextView.spellCheckingType = UITextSpellCheckingType.Yes
// myTextView.autocapitalizationType = UITextAutocapitalizationType.None

// Add Tap gesture to be able to dismiss keyboard when user taps away
// You will need to declare a new function "tappedAwayFunction"
let myGesture = UITapGestureRecognizer(target: self, action: "tappedAwayFunction:")
self.view.addGestureRecognizer(myGesture)


* Swift 3 + :- 

 // Make current ViewController respond to UITextViewDelegate events
        myTextView.delegate = self
        
        // Update UITextView content
        myTextView.text = "In this video we are going to edit UITextView from our Swift code. www.swiftdeveloperblog.com"
        
        // Change UITextView background colour
        myTextView.backgroundColor = UIColor.yellow
        
        // User RGB colour
        myTextView.backgroundColor = UIColor(red: 39/255, green: 53/255, blue: 182/255, alpha: 1)
        
        // Update UITextView font size and colour
        myTextView.font = UIFont.systemFont(ofSize: 20)
        myTextView.textColor = UIColor.white
        
        myTextView.font = UIFont.boldSystemFont(ofSize: 20)
        myTextView.font = UIFont(name: "Verdana", size: 17)
        
        // Make UITextView Editable
        myTextView.isEditable = true
        
        // Capitalize all characters user types
        myTextView.autocapitalizationType = UITextAutocapitalizationType.allCharacters
        
        // Make web links clickable
        myTextView.isSelectable = true
        myTextView.isEditable = false
        myTextView.dataDetectorTypes = UIDataDetectorTypes.link
        
        // Make UITextView corners rounded
        myTextView.layer.cornerRadius = 10
        
        // Enable auto-correction and Spellcheck
        myTextView.autocorrectionType = UITextAutocorrectionType.yes
        myTextView.spellCheckingType = UITextSpellCheckingType.yes
        // myTextView.autocapitalizationType = UITextAutocapitalizationType.None
        
        // Add Tap gesture to be able to dismiss keyboard when user taps away
        // You will need to declare a new function "tappedAwayFunction"
        let myGesture = UITapGestureRecognizer(target: self, action: "tappedAwayFunction:")
        self.view.addGestureRecognizer(myGesture)






No comments:

Post a Comment