Sanjaysinh Chauhan
Sanjaysinh Chauhan

Reputation: 201

How can we create IBInspectable like checkmark?

I created lots of IBInspectable. But today, I observed that Xcode having some properties like this:

enter image description here

In the link, I marked rectangle box. I want to create custom IBInspectable like that. I don't know that is possible or not.

Any help would be appreciated.

Upvotes: 9

Views: 1575

Answers (1)

Rohit Kardani
Rohit Kardani

Reputation: 105

Follow below steps to create Custom IBDesignable

Step 1:

enter image description here

Step 2:

enter image description here

step 3: add this code in created customTextView file

import UIKit

@IBDesignable
class customTextView: UITextView {

@IBInspectable var cornerRadius: CGFloat = 4.0 {
    didSet{
        layer.cornerRadius = cornerRadius
    }
}

@IBInspectable var borderWidth: CGFloat = 0.0 {
    didSet{
        layer.borderWidth = borderWidth
    }
}

@IBInspectable var borderColor: UIColor = UIColor.clear {
    didSet{
        layer.borderColor = borderColor.cgColor
    }
}

@IBInspectable var shadowOpacity: Float = 0 {
    didSet{
        layer.shadowOpacity = shadowOpacity
    }
}

@IBInspectable var shadowColor: UIColor = UIColor.clear {
    didSet{
        layer.shadowColor = shadowColor.cgColor
    }
}

@IBInspectable var shadowOffSet: CGSize = CGSize.zero {
    didSet{
        layer.shadowOffset = shadowOffSet
    }
}

}

Step 4:

enter image description here

Step 5: Here you get you custom fields

enter image description here

Upvotes: 0

Related Questions