0

Is there any way to add section name in newly added @IBDesignable properties for better readability.

//
//MARK: - Badge
//
@IBInspectable
var badgeColor:UIColor = UIColor.darkGray {
    didSet {
        updateView()
    }
}

@IBInspectable
var showBadgeOnIndex:Int = 0 {
    didSet {
        if showBadgeOnIndex >= buttons.count {
            showBadgeOnIndex = 0
        }
        updateView()
    }
}

@IBInspectable
var showAllBadge:Bool = false {
    didSet {
        updateView()
    }
}

@IBInspectable
var hideAllBadge:Bool = true {
    didSet {
        updateView()
    }
}

ex:

Example attributes in the Attributes inspector

In the picture above, the view properties have the section name View.

Any help would be appreciated.

I already know that the name of the custom class will appear as the section name in the Attributes Inspector.

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
iamVishal16
  • 1,780
  • 18
  • 40
  • 2
    You can create a subclass for it that could make it work. Each subclass will have its section name with its properties designable. – Larme Dec 12 '17 at 11:17
  • @Larme Okay but creating so many subclasses for small set of operation not so good approach. thanks by the way for the solution. – iamVishal16 Dec 12 '17 at 11:22
  • Indeed, that's not a good idea, just to have a "opinion based better looking window in Interface Builder". But since the section title take the name of the class, it have to be a subclass to get it work as you want. If you were having multiple composants (with a sense at each step of the "inheritance family tree), then it could be ok to do so. – Larme Dec 12 '17 at 13:02
  • @Larme Thanks for the approach. – iamVishal16 Dec 13 '17 at 06:12

2 Answers2

1

Sections and their titles in the Attributes inspector are generated based on what exact classes the properties in that section belong to. There is no way to change this behavior.

However, Xcode automatically groups the inspectable properties that have similar names. Those groups are separated with a line. This behavior is also visible in your example picture:

separator between automatically created groups

Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223
0

By default your classname (A name of your custom class) becomes a title for IBDesignable properties

Here is reference documents, what you want. IBInspectable / IBDesignable

enter image description here

Krunal
  • 77,632
  • 48
  • 245
  • 261