Я хочу держать в переменных и добавлять новые функции в UIButton.Я пытался с расширением, но с set и get, я не смог сделать это.Я пытался создать пользовательский класс UIButton, но теперь я не могу использовать свои функции и переменные в моем новом классе кнопок в xcode.
Как я могу это сделать?Спасибо ...
class ViewController: UIViewController {
//I want to be able to initialize MyUIButton like below
@IBOutlet weak var button11: MyUIButton!
override func viewDidLoad() {
super.viewDidLoad()
//initialize the databaseAccessor class
let appDelegate = UIApplication.shared.delegate as! AppDelegate
let context = appDelegate.persistentContainer.viewContext
DatabaseAccessor.shared = DatabaseAccessor(delegate: appDelegate, viewContext: context)
// the code that I want to work is below
button11.getLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
import UIKit
@IBDesignable
class MyUIButton: UIButton {
/*
// Only override draw() if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func draw(_ rect: CGRect) {
// Drawing code
}
*/
override func awakeFromNib() {
super.awakeFromNib()
}
@IBInspectable var purposeName = ""
private var purposeIcon = ""
private var location = 0
func setPurposeName(name: String){
purposeName = name
}
func getPurposeName()-> String{
return purposeName
}
func setPurposeIcon(name: String){
purposeIcon = name
}
func getPurposeIcon()-> String{
return purposeIcon
}
func setLocation(location: Int){
self.location = location
}
func getLocation()-> Int{
return location
}
}
Я сделал это, но ни один из них не сработал ... Я хочу использовать функции, которые я сделал в viewController.Как