swift - 从哪里调用分段的 Control.remove Borders()?

标签 swift call uisegmentedcontrol

当我在 Xcode 中创建扩展并需要调用时:

segmentedControl.removeBorders()

我应该从哪里调用它?在 View Controller 的 Swift 文件的 viewDidLoad 中?作为 View Controller 的 Swift 文件中的覆盖函数?在 viewDidLoad 之后插入它给我一个“方法‘segmentedControl’被用作属性;添加 () 来调用它”错误,当我添加括号时它给了我一个

"Value of tuple type '()' has no member 'removeBorders'" error.

命名有问题吗?我将删除边框/分隔线的 .swift 命名为“UISegmentedControl+removeborders.swift”。我是个彻头彻尾的 n00b,如果这有助于解释我为什么坚持这一点的话。任何帮助将不胜感激!谢谢!

引用:针对此问题列出的关于从 UISegmentedControl 中删除边框/分隔线的第三个答案:Remove UISegmentedControl separators completely. (iphone)

最佳答案

在我当前的项目中,我对其进行了子类化,因此调用是在初始化程序中进行的:

class SegmentedControl: UISegmentedControl {
    override init(items: [Any]?) {
        super.init(items: items)
        segmentedControlInit()
    }
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        segmentedControlInit()
    }
    private func segmentedControlInit() {
        removeBorders()
    }
}

但是从 viewDidLoad 执行它也应该没问题。

关于swift - 从哪里调用分段的 Control.remove Borders()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40835375/

相关文章:

ios - 使用 NSURLSessionDownloadTask 时使用 resumeData 的正确方法是什么?

iphone - UISegmentedControl:以编程方式设置索引?

ios - UISegmentedControl 的动画栏按钮没有移动?

android - 在我的 Activity 中打开 Android 通话记录

c - 如果给出了错误的输入,我的函数应该包含什么才能返回 -1.0 的值?

javascript - jQuery 在多个元素上调用函数的更好方法?

ios - 多行 UISegmentedControl 文本

arrays - 如何更新swift字典值

IOS/objective-C : Set NSItemProvider

ios - 当我按下按钮时如何只做一件事?