2

I have created a custom IBDesignable UISegmentedControl class. The class has no build errors but has warnings, it does not update inside of Xcode. There are the warnings, see the screenshot below.

@IBDesignable open class UISegmentedControlBorderless : UISegmentedControl {

    @IBInspectable var borderColor:UIColor = UIColor.white {
        didSet {
            setupUI()
        }
    }
    @IBInspectable var textColor:UIColor = UIColor.white {
        didSet {
            setupUI()
        }
    }
    @IBInspectable var textSelectedColor:UIColor = UIColor.red {
        didSet {
            setupUI()
        }
    }

    required public init?(coder aDecoder:NSCoder) {
        super.init(coder:aDecoder)
        setupUI()
    }

    override init(frame:CGRect) {
        super.init(frame:frame)
        setupUI()
    }

    override open func awakeFromNib() {
        super.awakeFromNib()
        setupUI()
    }

    override open func prepareForInterfaceBuilder() {
        super.prepareForInterfaceBuilder()

        setupUI()
    }

    fileprivate func setupUI() {
        tintColor = borderColor
        let attributes = [NSAttributedStringKey.foregroundColor: textColor]
        let attributes2 = [NSAttributedStringKey.foregroundColor: textSelectedColor]

        setTitleTextAttributes(attributes, for: .normal)
        setTitleTextAttributes(attributes2, for: .selected)

    }  
}

Warnings:

xcode screenshot

Unticking inherit module

enter image description here

Sateesh Yemireddi
  • 4,289
  • 1
  • 20
  • 37
daviddna
  • 163
  • 2
  • 7

1 Answers1

0

Based on the first warning in your screenshot, Xcode is not finding your UISegementedControl subclass. This is commonly caused by not setting the correct module where the class is defined, and since your subclass is defined as open, it seems likely that you have it in a framework or module outside of the target app.

So, make sure where you set the custom class for the segmented control on the storyboard that you also selected the correct module for where the subclass is defined, and you probably want to uncheck "inherit module from target" in order to do so:

Custom Class Tab

Daniel Hall
  • 13,457
  • 4
  • 41
  • 37
  • Its inside the same project. If i untick inherit module and select the module, i get a designables error – daviddna Jan 23 '19 at 07:23