[英]iOS - get frame of UIView at runtime which was created with Interface Builder
我正在使用图形来可视化一些数据的应用程序。 我为此使用了这个漂亮的Scrollable-GraphView: https : //github.com/philackm/Scrollable-GraphView
因为这只是从UIScrollView继承的类,所以无法在Interface Builder中使用它(它也没有实现init(withCoder :)函数)。
我现在想使用Interface Builder添加一个UIView,它具有在运行时正确调整大小的所有必要约束。 如何在运行时用GraphView“替换”该UIView?
此方法用于在运行时创建图形:
private func createDarkGraph(frame: CGRect) -> ScrollableGraphView {
let graphView = ScrollableGraphView(frame: frame)
// ... some customization
return graphView
}
在界面构建器中,您可以拖动UIScrollView并像普通的UIScrollView一样设置约束,然后将该类设置为ScrollableGraphView
,选择正确的模块(导入!请参见此链接, 在Interface Builder文件中XCODE 7.1 Swift 2 Unknown class )。 如果从接口构建器(创建插座.etc)获取scrollView实例,则它必须是ScrollableGraphView
的实例。 那应该很好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.