【发布时间】:2021-12-06 10:33:58
【问题描述】:
我正在用 Swift 开发一个图形库。代码无法共享,但我做了一个示例here(参见按钮示例,单选按钮专用于另一个问题)。
我想为我的组件创建一个命名空间 MyGraphicLibrary:MyGraphicLibrary.Button 而不是 MyGraphicLibraryButton
示例 pod 有两个类:
// Independent class
@IBDesignable public class CustomButton: UIButton {
...
}
// Namespace for my components
public class MyGraphicLibrary: NSObject {
}
// Namespaced button
public extension MyGraphicLibrary {
@objc(MyGraphicLibraryButton) @IBDesignable class Button: UIButton {
...
}
}
CustomButton 类在界面构建器中的行为符合预期:我可以轻松地将自定义类添加到按钮(请参阅Main.storyboard)。
对于嵌套类,无法使用其正常名称(Button 或 MyGraphicLibrary.Button)进行设置。
唯一的办法就是设置类@objc名称MyGraphicLibraryButton;没有自动补全,模块必须设置为none(看起来很废话,该类属于GraphicLibrary模块)。删除 @objc 名称没有区别。
有没有办法让Interface Builder正确处理嵌套类?
【问题讨论】:
标签: ios swift inner-classes ibdesignable