How can we create IBInspectable like checkmark?
Asked Answered
H

1

9

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.

Hindi answered 16/3, 2018 at 14:49 Comment(3)
You can't have a checkbox. Creating a bool @IBInspectable will give you an on/off drop-down control in the inspector.Dian
on/off drop means Its Bool @IBInspectable that I know. But I just want to know checkbox is possible or not. Thanks for your replyHindi
@SanjaysinhChauhan Please check my answer. Thank you.Scarabaeoid
S
0

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

Scarabaeoid answered 18/3, 2018 at 14:47 Comment(2)
@Sanjaysinh Chauhan if you get your answer then please accept answer and upvote thanksScarabaeoid
Thanks for your answer. I know how to create IBInspectable. But I want to create an IBInspectable show in the above question link. In the link, a 2nd rounded box has checkmark IBInspectable. I want to create like that. I don't know that is possible or not. So, Please answer if you have any alternate way.Hindi

© 2022 - 2025 — McMap. All rights reserved.