Tuesday, March 1, 2016

Draw a red border around your UIView for debugging purposes

A lot of the times, you're dealing with UITextViews and UITextFields that have the same

A lot of the times, you're dealing with UITextViews and UITextFields that have the same white background and border as the superviews they sit on top of. It's helpful every now and then to make sure they're obeying the constraints you want them to have. In my case, I made a self-contained UITextView that has a placeholder functionality but the textView wasn't constraining to the size of its container view.



Ahh... needed better constraints:

func applyConstraintsToTextView() {

    if let validTextView = self.placeholderTextView {
        let viewsDictionary = ["textView":validTextView]
        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|[textView]|", options: [], metrics: nil, views: viewsDictionary))
        self.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("V:|[textView]|", options: [], metrics: nil, views: viewsDictionary))

Now add this extension to UIView

extension UIView {

func drawRedBorder() {
    self.layer.borderColor = UIColor.redColor().CGColor
    self.layer.borderWidth = 1.0;

simply call it on the view (any UIView subclass) and see where the borders are landing.


Much better...



  1. To buy a second hand mobile is not easy when you have no idea about the mobile phone price. So you can search in Quikads; a classified ads platform in Bangladesh. Where you will get so many ideas about second hand mobile phone prices in Bangladesh.

  2. Bike mayhem is a free and easy to use modification for Android that allows users to do things like speed up, slow down, or reverse the direction of their bike while riding. This app is great for those who want to have some fun while cycling, and it's also great for people who want to learn how to use their bike more efficiently. For more Info visit us at https://apktreee.com/bike-mayhem-mod-apk/


Mvvm on Mobile?

Here's my talk from Houston Tech Fest 2017. Recorded Talk: Slides: https://speakerdeck.com/markawil/mvvm-and-mobile-dont-do-it...