gpt4 book ai didi

ios - 如何将触摸 socket 添加到自定义 UIView?

转载 作者:行者123 更新时间:2023-11-28 15:20:10 26 4
gpt4 key购买 nike

我创建了以下自定义 UIVIew:

//
// YearSelectorSegControl.swift
// OurDailyStrength iOS
//
// Created by Rob Avery on 8/28/17.
// Copyright © 2017 Rob Avery. All rights reserved.
//

import UIKit

@IBDesignable
class YearSelectorSegControl: UIView {

var buttons = [UIButton]()
var selector: UIView!
var sv: UIStackView!

var currentPosition: Int = 0

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

@IBInspectable
var borderColor: UIColor = UIColor.clear {
didSet {
layer.borderColor = borderColor.cgColor
}
}

@IBInspectable
var textColor: UIColor = .lightGray {
didSet {
updateView()
}
}

@IBInspectable
var textBackground: UIColor = .clear {
didSet {
updateView()
}
}

func updateView() {
// ... code here ...
}

override func draw(_ rect: CGRect) {
layer.cornerRadius = 0
}
}

当我转到 Interface Builder 并尝试将此 UIView 连接到 Controller 时,唯一允许的是 socket 。我希望能够在触摸此自定义 UIView 时将其连接到一个函数。我该怎么做?

最佳答案

你必须继承 UIControl 而不是 UIView

@IBDesignable
class YearSelectorSegControl: UIControl {
...
}

关于ios - 如何将触摸 socket 添加到自定义 UIView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46145090/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com