海森堡
Heisenberg
是一个用于使用Swift
创建/使用化学结构的iOS
UI库。它使用HeisenbergDirectionalStructure
表示方向性结构,而使用HeisenbergLinearStructure
表示线性结构。您可以将两个元素之间的键作为SingleBond
、DoubleBond
或TripleBond
来改变。
HeisenbergDirectionalStructure
基于Graph
,而HeisenbergLinearStructure
基于SinglyLinkedList
。您可以使用HeisenbergLinearStructure
仅创建x轴线性结构,但使用HeisenbergDirectionalStructure
可以创建/构建Graph
可以做的一切。
HeisenbergLinearStructure
let heisenberg = HeisenbergLinearStructure(with: hidyrogen1, itemSize: 40)
heisenberg.linkTo(with: oxgen, with: .SingleBond) { (structure) in
// structure callback
}.linkTo(with: hidyrogen2, with: .TripleBond) { (structure) in
}.linkTo(with: tAtom, with: .TripleBond) { (structure) in
}.linkTo(with: babyAtom, with: .TripleBond) { (structure) in
}
let board = HeisenbergBoard<String>(with: heisenberg, with: .cyan)
let boardView = board.drawBoard()
view.addSubview(boardView)
HeisenbergDirectionalStructure
let directional = HeisenbergDirectionalStructure(with: cAtom, itemSize: 50)
directional.linkWith(from: cAtom, to: nAtom, way: .next, bond: .SingleBond, bondColor: .black) { (structure) in
}.linkWith(from: nAtom, to: h1Atom, way: .crossUpForward, bond: .SingleBond, bondColor: .black) { (structure) in
}.linkWith(from: nAtom, to: h3Atom, way: .crossDownForward, bond: .SingleBond, bondColor: .black) { (structure) in
}.linkWith(from: nAtom, to: h2Atom, way: .next, bond: .SingleBond, bondColor: .black) { (structure) in
}.linkWith(from: cAtom, to: loveAtom, way: .downward, bond: .TripleBond, bondColor: .darkGray) { (structure) in
}
let board = HeisenbergBoard<String>(with: directional, with: .lightGray)
let boardView = board.drawBoard()
view.addSubview(boardView)
原子之间的键合
您可以使用元素键将两个或多个原子绑定在一起。有一个用于键合方式的列表。
public enum StructuralWay: String{
case upward = "up"
case downward = "down"
case next = "next"
case angular = "angular"
case crossDownForward = "cross_down_forward"
case crossUpForward = "cross_up_forward"
case crossDownBackward = "cross_back_down"
case crossUpBackward = "cross_back_up"
}
海森堡板
HeisenbergBoard
是一个用于创建处理化学结构 UI 结构的类。您可以选择任何 HeisenbergLinearStructure
或 HeisenbergDirectionalStructure
,并必须选择板的一个 backgroundColor
。然后,drawBoard()
方法会返回结构的一个 UIView
。
let board = HeisenbergBoard<String>(with: directional, with: .lightGray)
let boardView = board.drawBoard()
示例
我已经添加了一些生成 海森堡
的测试函数。您可以检查它们。要运行示例项目,请首先克隆存储库,然后从示例目录运行 pod install
。
要求
安装
Heisenberg 可通过 CocoaPods 获取。要安装它,只需将以下行添加到您的 Podfile 中
pod 'Heisenberg'
作者
eliakorkmaz, [email protected]
许可证
Heisenberg 在 MIT 许可证下可用。有关更多信息,请参阅许可证文件。