@@ -12,44 +12,113 @@ enum ButtonType {
1212}
1313
1414enum ButtonPosition {
15- case top_left, bottom_right, bottom_left, midle_left, midle_bottom
15+ case top_left, bottom_right, bottom_left, midle_left, midle_bottom, top_right
1616}
1717
18+
1819struct Button {
1920 var buttonPosition : ButtonPosition !
2021 var buttonType : ButtonType !
21- var image : UIImage !
22- var tintColor : UIColor !
23- var buttonSize : CGSize !
22+ var button : UIButton !
23+ var isOverrideSize : Bool !
24+ private let _defaultbutton : UIButton = {
25+ let button = UIButton ( )
26+ button. setImage ( UIImage ( systemName: " square.fill " ) !, for: . normal)
27+ button. frame. size = CGSize ( width: 16 , height: 16 )
28+ return button
29+ } ( )
30+
2431 init ( buttonPosition: ButtonPosition ! ,
25- buttonType: ButtonType ! , tintColor: UIColor = . black,
26- image: UIImage = UIImage ( systemName: " square.fill " ) !, buttonSize: CGSize ? = nil ) {
32+ buttonType: ButtonType ! ,
33+ button: UIButton ? = nil ,
34+ isOverrideSize: Bool = false
35+ ) {
2736 self . buttonPosition = buttonPosition
2837 self . buttonType = buttonType
29- self . image = image
30- self . tintColor = tintColor
31- self . buttonSize = buttonSize
38+
39+ self . button = button ?? _defaultbutton
40+ self . isOverrideSize = isOverrideSize
3241 }
3342}
3443
3544open class Configuration {
3645
37- public init ( ) { }
38-
39- var activeButtons : [ Button ] ! = [ Button ( buttonPosition: . top_left, buttonType: . remove, image: UIImage ( systemName: " trash " ) !) ,
40- Button ( buttonPosition: . bottom_right, buttonType: . scale, image: UIImage ( systemName: " arrow.up.left.and.arrow.down.right " ) !) ,
41- Button ( buttonPosition: . bottom_left, buttonType: . rotate, image: UIImage ( systemName: " gobackward " ) !) ,
42- Button ( buttonPosition: . midle_left, buttonType: . stretch_width, image: UIImage ( systemName: " square.fill " ) !) ,
43- Button ( buttonPosition: . midle_bottom, buttonType: . stretch_height, image: UIImage ( systemName: " square.fill " ) !)
44- ]
46+ var activeButtons : [ Button ] ! = [ ]
4547 var minimumSize : CGFloat ! = 16 * 4
4648 public var insetMarging : CGFloat ! = 16
4749 public var boarderColor : UIColor ! = . darkGray
4850 public var borderWidth : CGFloat ! = 2
49- public var buttonSize : CGSize ! = CGSize ( width: 16 , height: 16 ) {
51+ public var buttonSize : CGSize ! = CGSize ( width: 28 , height: 28 ) {
5052 didSet{
5153 minimumSize = buttonSize. width * 4
5254 }
5355 }
5456
57+ private lazy var _trashButton : UIButton = {
58+ let button = UIButton ( )
59+ button. setImage ( UIImage ( systemName: " trash " ) !, for: . normal)
60+ button. frame. size = CGSize ( width: 16 , height: 16 )
61+ buttonDecorator ( button)
62+ return button
63+ } ( )
64+ private lazy var _scaleButton : UIButton = {
65+ let button = UIButton ( )
66+ button. setImage ( UIImage ( systemName: " arrow.up.left.and.arrow.down.right " ) !, for: . normal)
67+ button. frame. size = CGSize ( width: 16 , height: 16 )
68+ buttonDecorator ( button)
69+ return button
70+ } ( )
71+
72+ private lazy var _rotateButton : UIButton = {
73+ let button = UIButton ( )
74+ button. setImage ( UIImage ( systemName: " gobackward " ) !, for: . normal)
75+ button. frame. size = CGSize ( width: 16 , height: 16 )
76+ buttonDecorator ( button)
77+ return button
78+ } ( )
79+
80+ private lazy var _stretchWidthButton : UIButton = {
81+ let button = UIButton ( )
82+ button. setImage ( UIImage ( systemName: " square.fill " ) !, for: . normal)
83+ button. frame. size = CGSize ( width: 16 , height: 16 )
84+ buttonDecorator ( button)
85+ return button
86+ } ( )
87+
88+ private lazy var _stretchHeightButton : UIButton = {
89+ let button = UIButton ( )
90+ button. setImage ( UIImage ( systemName: " square.fill " ) !, for: . normal)
91+ button. frame. size = CGSize ( width: 16 , height: 16 )
92+ buttonDecorator ( button)
93+ return button
94+ } ( )
95+ private lazy var _flipImageButton : UIButton = {
96+ let button = UIButton ( )
97+ button. setImage ( UIImage ( systemName: " flip.horizontal.fill " ) !, for: . normal)
98+ button. frame. size = CGSize ( width: 16 , height: 16 )
99+ buttonDecorator ( button)
100+ return button
101+ } ( )
102+
103+
104+ private func buttonDecorator( _ button: UIButton ) {
105+ button. layer. shadowColor = UIColor ( red: 0 , green: 0 , blue: 0 , alpha: 0.25 ) . cgColor
106+ button. layer. shadowOffset = CGSize ( width: 0.0 , height: 0.0 )
107+ button. layer. shadowOpacity = 1.0
108+ button. layer. shadowRadius = 4.0
109+ button. layer. masksToBounds = false
110+ button. layer. cornerRadius = buttonSize. width/ 2
111+ button. backgroundColor = . white
112+ }
113+
114+ public init ( ) {
115+ activeButtons = [ Button ( buttonPosition: . top_left, buttonType: . remove, button: _trashButton) ,
116+ Button ( buttonPosition: . bottom_right, buttonType: . scale, button: _scaleButton) ,
117+ Button ( buttonPosition: . bottom_left, buttonType: . rotate, button: _rotateButton) ,
118+ Button ( buttonPosition: . midle_left, buttonType: . stretch_width, button: _stretchWidthButton) ,
119+ Button ( buttonPosition: . midle_bottom, buttonType: . stretch_height, button: _stretchHeightButton) , Button ( buttonPosition: . top_right, buttonType: . flip, button: _flipImageButton) ]
120+ }
121+
122+
123+
55124}
0 commit comments