Reputation: 757
I have created a custom UISegment Control
@IBDesignable class CardsSegmentedControl: UIControl {
private var labels = [UILabel]()
var thumbView = UIView()
var items: [String] = ["Saved Cards", "Add Card"] {
didSet {
setupLabels()
}
}
var selectedIndex : Int = 0 {
didSet {
displayNewSelectedIndex()
}
}
....
}
Now I wish to change the value of the variable selectedIndex
in the viewController where I am adding this custom segment control in.
I guess it is a problem of how to access/change variables from another class.
I tried to create a class func
which would set the value of the selectedIndex
but I cannot get it to access the selectedIndex
variable either.
Still pretty new to Swift so please bear with me.
Upvotes: 2
Views: 6977
Reputation: 657
// Inside your ViewController class, create a new instance of your custom class
var cardSegmentedControl = CardSegmentedControl()
// here, change its property value
cardSegmentedControl.selectedIndex = 1
Upvotes: 3