top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

In xcode 6 how to make display my custom view's properties in attribute inspector

0 votes
670 views

I have created my own custom view using view class. Now i want to make visible my custom properties on my view's attribute inspector.

posted Aug 19, 2014 by Arun

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

IBInspectable exposes class properties in the interface builder Attribute Inspector, and IBDesignable updates the view in realtime..

class OverCustomizableView : UIView {
    @IBInspectable var integer: Int = 0
    @IBInspectable var float: CGFloat = 0
    @IBInspectable var double: Double = 0
    @IBInspectable var point: CGPoint = CGPointZero
    @IBInspectable var size: CGSize = CGSizeZero
    @IBInspectable var customFrame: CGRect = CGRectZero
    @IBInspectable var color: UIColor = UIColor.clearColor()
    @IBInspectable var string: String = "We ❤ Swift"
    @IBInspectable var bool: Bool = false
}

Add logic for the layer properties
Add property observers for each property and update the layer accordingly.

class CustomView : UIView {
    @IBInspectable var borderColor: UIColor = UIColor.clearColor() {
        didSet {
            layer.borderColor = borderColor.CGColor
        }
    }

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

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

Build the framework by pressing ⌘ Cmd + B.

answer Sep 10, 2014 by Raju
Similar Questions
+2 votes

I created custom view class.

import UIKit

class CustomView: UIView {

    init(frame: CGRect) {
        super.init(frame: frame)
        // Initialization code
    }

    /*
    // Only override drawRect: if you perform custom drawing.
    // An empty implementation adversely affects performance during animation.
    override func drawRect(rect: CGRect)
    {
        // Drawing code
    }
    */

}

But i don't know how to include created custom view in Storyboard because i heard that we can add custom views in storyboard design.

+1 vote

How to declare single parameter which accept multiple values.

+1 vote

How to use default values for parameter in function. What will happens when value is not passed for a default parameters.

0 votes

I am facing situation to use external parameter name to a function parameter name .. How to achieve this

0 votes

Is it possible to set multiple return type for function in SWIFT. If yes please provide me syntax .

...