From 1a6cfc784f1818a2140239ce54aaabc84a24c8e7 Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 12:24:39 +0100 Subject: [PATCH 1/8] Add left button --- Examples/Examples/ViewController.swift | 9 +- MessageViewController/MessageView.swift | 121 ++++++++++++++++++------ 2 files changed, 99 insertions(+), 31 deletions(-) diff --git a/Examples/Examples/ViewController.swift b/Examples/Examples/ViewController.swift index 1b343dd..1645e40 100644 --- a/Examples/Examples/ViewController.swift +++ b/Examples/Examples/ViewController.swift @@ -25,14 +25,17 @@ class ViewController: MessageViewController, UITableViewDataSource, UITableViewD borderColor = .lightGray + messageView.set(buttonTitle: "A", for: .normal, type: .left) + messageView. + messageView.inset = UIEdgeInsets(top: 8, left: 16, bottom: 8, right: 16) messageView.textView.placeholderText = "New message..." messageView.textView.placeholderTextColor = .lightGray messageView.font = UIFont.systemFont(ofSize: 17) - messageView.set(buttonTitle: "Send", for: .normal) - messageView.addButton(target: self, action: #selector(onButton)) - messageView.buttonTint = .blue +// messageView.set(buttonTitle: "Send", for: .normal) +// messageView.addButton(target: self, action: #selector(onButton)) +// messageView.buttonTint = .blue messageAutocompleteController.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell") messageAutocompleteController.tableView.dataSource = self diff --git a/MessageViewController/MessageView.swift b/MessageViewController/MessageView.swift index f8d458a..45727eb 100644 --- a/MessageViewController/MessageView.swift +++ b/MessageViewController/MessageView.swift @@ -13,21 +13,34 @@ public final class MessageView: UIView, MessageTextViewListener { public let textView = MessageTextView() internal weak var delegate: MessageViewDelegate? - internal let button = UIButton() + internal let leftButton = UIButton() + internal let rightButton = UIButton() internal let UITextViewContentSizeKeyPath = #keyPath(UITextView.contentSize) internal let topBorderLayer = CALayer() internal var contentView: UIView? - internal var buttonAction: Selector? + internal var leftButtonAction: Selector? + internal var rightButtonAction: Selector? + + public enum buttonType { + case left + case right + } internal override init(frame: CGRect) { super.init(frame: frame) backgroundColor = .white + addSubview(leftButton) addSubview(textView) - addSubview(button) + addSubview(rightButton) layer.addSublayer(topBorderLayer) + //Set action button + leftButton.imageEdgeInsets = .zero + leftButton.titleEdgeInsets = .zero + leftButton.contentEdgeInsets = .zero + // setup text view textView.contentInset = .zero textView.textContainerInset = .zero @@ -47,9 +60,9 @@ public final class MessageView: UIView, MessageTextViewListener { textView.layoutManager.usesFontLeading = true // setup send button - button.titleEdgeInsets = .zero - button.contentEdgeInsets = .zero - button.imageEdgeInsets = .zero + rightButton.imageEdgeInsets = .zero + rightButton.titleEdgeInsets = .zero + rightButton.contentEdgeInsets = .zero updateEmptyTextStates() } @@ -92,22 +105,62 @@ public final class MessageView: UIView, MessageTextViewListener { didSet { setNeedsLayout() } } - public func set(buttonIcon: UIImage?, for state: UIControlState) { - button.setImage(buttonIcon, for: state) + public func set(buttonIcon: UIImage?, for state: UIControlState, type: buttonType) { + switch type { + case .left: + setLeft(buttonIcon: buttonIcon, for: state) + break + case .right: + setRight(buttonIcon: buttonIcon, for: state) + break + } + } + + public func set(buttonTitle: String, for state: UIControlState, type: buttonType) { + switch type { + case .left: + setLeft(buttonTitle: buttonTitle, for: state) + break + case .right: + setRight(buttonTitle: buttonTitle, for: state) + break + } + } + + private func setLeft(buttonIcon: UIImage?, for state: UIControlState) { + leftButton.setImage(buttonIcon, for: state) buttonLayoutDidChange() } - public func set(buttonTitle: String, for state: UIControlState) { - button.setTitle(buttonTitle, for: state) + private func setLeft(buttonTitle: String, for state: UIControlState) { + leftButton.setTitle(buttonTitle, for: state) buttonLayoutDidChange() } - public var buttonTint: UIColor { - get { return button.tintColor } + private func setRight(buttonIcon: UIImage?, for state: UIControlState) { + rightButton.setImage(buttonIcon, for: state) + buttonLayoutDidChange() + } + + private func setRight(buttonTitle: String, for state: UIControlState) { + rightButton.setTitle(buttonTitle, for: state) + buttonLayoutDidChange() + } + + public var leftButtonTint: UIColor { + get { return leftButton.tintColor } + set { + leftButton.tintColor = newValue + leftButton.setTitleColor(newValue, for: .normal) + leftButton.imageView?.tintColor = newValue + } + } + public var rightButtonTint: UIColor { + get { return rightButton.tintColor } set { - button.tintColor = newValue - button.setTitleColor(newValue, for: .normal) - button.imageView?.tintColor = newValue + rightButton.tintColor = newValue + rightButton.setTitleColor(newValue, for: .normal) + rightButton.imageView?.tintColor = newValue } } @@ -132,12 +185,12 @@ public final class MessageView: UIView, MessageTextViewListener { } public func addButton(target: Any, action: Selector) { - button.addTarget(target, action: action, for: .touchUpInside) - buttonAction = action + rightButton.addTarget(target, action: action, for: .touchUpInside) + rightButtonAction = action } public override var keyCommands: [UIKeyCommand]? { - guard let action = buttonAction else { return nil } + guard let action = rightButtonAction else { return nil } return [UIKeyCommand(input: "\r", modifierFlags: .command, action: action)] } @@ -161,23 +214,34 @@ public final class MessageView: UIView, MessageTextViewListener { ) let insetBounds = UIEdgeInsetsInsetRect(safeBounds, inset) - let buttonSize = button.bounds.size + let leftButtonSize = leftButton.bounds.size + let rightButtonSize = rightButton.bounds.size + + // adjust by bottom offset so content is flush w/ text view + let leftButtonFrame = CGRect( + x: insetBounds.minX, + y: insetBounds.minY, + width: leftButtonSize.width, + height: leftButtonSize.height + ) + leftButton.frame = leftButtonFrame let textViewFrame = CGRect( - x: insetBounds.minX, + x: leftButtonFrame.maxX + buttonLeftInset, y: insetBounds.minY, - width: insetBounds.width - buttonSize.width - buttonLeftInset, + width: insetBounds.width - leftButtonSize.width - buttonLeftInset - rightButtonSize.width, height: textViewHeight ) textView.frame = textViewFrame // adjust by bottom offset so content is flush w/ text view - button.frame = CGRect( + let rightButtonFrame = CGRect( x: textViewFrame.maxX + buttonLeftInset, - y: textViewFrame.maxY - buttonSize.height + button.bottomHeightOffset, - width: buttonSize.width, - height: buttonSize.height + y: textViewFrame.maxY - rightButtonSize.height + rightButton.bottomHeightOffset, + width: rightButtonSize.width, + height: rightButtonSize.height ) + rightButton.frame = rightButtonFrame let contentY = textViewFrame.maxY + inset.bottom contentView?.frame = CGRect( @@ -217,12 +281,13 @@ public final class MessageView: UIView, MessageTextViewListener { internal func updateEmptyTextStates() { let isEmpty = text.isEmpty - button.isEnabled = !isEmpty - button.alpha = isEmpty ? 0.25 : 1 + rightButton.isEnabled = !isEmpty + rightButton.alpha = isEmpty ? 0.25 : 1 } internal func buttonLayoutDidChange() { - button.sizeToFit() + leftButton.sizeToFit() + rightButton.sizeToFit() setNeedsLayout() } From 26d3cc5e38eac909ae6305eaba30ce9b9c3acb1e Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 12:26:49 +0100 Subject: [PATCH 2/8] Changed minimum requirement to iOS 9.0 --- MessageViewController.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MessageViewController.podspec b/MessageViewController.podspec index 57d0ca0..c5aadc0 100644 --- a/MessageViewController.podspec +++ b/MessageViewController.podspec @@ -7,6 +7,6 @@ Pod::Spec.new do |spec| spec.summary = 'Replacement for SlackTextViewController.' spec.source = { :git => 'https://github.com/GitHawkApp/MessageViewController.git', :tag => spec.version.to_s } spec.source_files = 'MessageViewController/*.swift' - spec.platform = :ios, '10.0' + spec.platform = :ios, '9.0' spec.swift_version = '4.0' end From b0e5adeb56d792c7524fc33e25b03e811da3cb74 Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 15:46:13 +0100 Subject: [PATCH 3/8] Added accessory button and flag to show or hide this button --- .idea/MessageViewController.iml | 2 + .idea/codeStyles/Project.xml | 32 +++ .idea/modules.xml | 8 + .idea/vcs.xml | 6 + .idea/workspace.xml | 139 +++++++++ .idea/xcode.xml | 4 + Examples/.idea/Examples.iml | 2 + Examples/.idea/codeStyles/Project.xml | 32 +++ Examples/.idea/modules.xml | 8 + Examples/.idea/vcs.xml | 6 + Examples/.idea/workspace.xml | 268 ++++++++++++++++++ Examples/.idea/xcode.xml | 4 + .../AppIcon.appiconset/Contents.json | 5 + .../Examples/Assets.xcassets/Contents.json | 6 + .../attachment.imageset/Contents.json | 22 ++ .../attachment.imageset/attachment.png | Bin 0 -> 1662 bytes .../attachment.imageset/attachment@2x.png | Bin 0 -> 3508 bytes Examples/Examples/ViewController.swift | 24 +- MessageViewController/MessageView.swift | 61 ++-- 19 files changed, 602 insertions(+), 27 deletions(-) create mode 100644 .idea/MessageViewController.iml create mode 100644 .idea/codeStyles/Project.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 .idea/workspace.xml create mode 100644 .idea/xcode.xml create mode 100644 Examples/.idea/Examples.iml create mode 100644 Examples/.idea/codeStyles/Project.xml create mode 100644 Examples/.idea/modules.xml create mode 100644 Examples/.idea/vcs.xml create mode 100644 Examples/.idea/workspace.xml create mode 100644 Examples/.idea/xcode.xml create mode 100644 Examples/Examples/Assets.xcassets/Contents.json create mode 100644 Examples/Examples/Assets.xcassets/attachment.imageset/Contents.json create mode 100644 Examples/Examples/Assets.xcassets/attachment.imageset/attachment.png create mode 100644 Examples/Examples/Assets.xcassets/attachment.imageset/attachment@2x.png diff --git a/.idea/MessageViewController.iml b/.idea/MessageViewController.iml new file mode 100644 index 0000000..74121dc --- /dev/null +++ b/.idea/MessageViewController.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..45f86bc --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..053c5f8 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/workspace.xml b/.idea/workspace.xml new file mode 100644 index 0000000..9d34f7a --- /dev/null +++ b/.idea/workspace.xml @@ -0,0 +1,139 @@ + + + + + + + + + + + + true + DEFINITION_ORDER + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 1519296008533 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Examples/.idea/xcode.xml b/Examples/.idea/xcode.xml new file mode 100644 index 0000000..bf7bc31 --- /dev/null +++ b/Examples/.idea/xcode.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json b/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json index 1d060ed..d8db8d6 100644 --- a/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json +++ b/Examples/Examples/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -84,6 +84,11 @@ "idiom" : "ipad", "size" : "83.5x83.5", "scale" : "2x" + }, + { + "idiom" : "ios-marketing", + "size" : "1024x1024", + "scale" : "1x" } ], "info" : { diff --git a/Examples/Examples/Assets.xcassets/Contents.json b/Examples/Examples/Assets.xcassets/Contents.json new file mode 100644 index 0000000..da4a164 --- /dev/null +++ b/Examples/Examples/Assets.xcassets/Contents.json @@ -0,0 +1,6 @@ +{ + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Examples/Assets.xcassets/attachment.imageset/Contents.json b/Examples/Examples/Assets.xcassets/attachment.imageset/Contents.json new file mode 100644 index 0000000..854865a --- /dev/null +++ b/Examples/Examples/Assets.xcassets/attachment.imageset/Contents.json @@ -0,0 +1,22 @@ +{ + "images" : [ + { + "idiom" : "universal", + "filename" : "attachment.png", + "scale" : "1x" + }, + { + "idiom" : "universal", + "filename" : "attachment@2x.png", + "scale" : "2x" + }, + { + "idiom" : "universal", + "scale" : "3x" + } + ], + "info" : { + "version" : 1, + "author" : "xcode" + } +} \ No newline at end of file diff --git a/Examples/Examples/Assets.xcassets/attachment.imageset/attachment.png b/Examples/Examples/Assets.xcassets/attachment.imageset/attachment.png new file mode 100644 index 0000000000000000000000000000000000000000..451b4d73600b1fc2a4569d7cca3b24e6aac13096 GIT binary patch literal 1662 zcmV-^27&pBP)Px*I7vi7RA>d&np;d9WfXvS7ciDqgT!dDiW>E$N+qp*FfoWL)&~W=lxi9;RUb4q z(a`ds;VPFGA6zYoKGPg zzt}$+&VT>UH|P9k{+Y$^`yZu&fq|-MG-+lpE)4_%y#Q=R@j#Nb=YSrVnVEUs4Xo%uz&s4Z4z4qjfSl3{{5M?9 zot>RxIVTkjsHdkVP*zs915LI%+SnNs{gLcJAj9O(B!4m2b(G8PE|#F}DA%1py|48} z0TP(f($beu@P1W9B+4DYow~cax;{4RCEwcGx~#IY@@~dF#dVRn;%cJe>?K=%cU9*f|fn{H#@iwEwcacb>hPLA+MrGc!ZZKHo1Xoi>N5^m~3XG4B z|2sA|_GT~`yb4RLw#S@9P&rQhhXu2cz?77fyv)M)sp0~IyEJuocfY4~smivtw&fKS z6`uojnLXwYtW;eP3#ny*arTUDnPz-HZ5RQVn3#yv*VoT5=SCYyg2z;{m~Z#ZT&QKZ zlW{Oar*|`-+2nle_Kv}@-o|>AvgYh$>3@-9B2g*%k&1cEYs%We1JY?I2h5OrKLso!6lNH#9sJ)DR=U(7tHMJY-1=C`uk+hH1<$FU__DH+S(4p`KlC= z>m$vJOb15#r}P}k7Yx>XTyz#iBw^{p?1$HvO6kMMxTG#;!|cL^Jl|*1bu(F5V6eus zlDE?$N2G^X?@uWsHJUjAfa*~4U zR$!QI1eH*>FrGlEz;MXCUXC8AMl)H=%`#YgJI|wMaslHCbUMSt0i^;%pVb^aKFQWH z?3tXonSf|=f{A2%tM0p>Zgtr#$} zzPQ{`RRpD6-xjsqO^Rh=PR&KJjOr#pKWG7IezY^H-LuIo!+EcU2r3^mB+P3{`U;>O zGm+wQ2Xr6{*Ko&g*K#76%rY_-%e_)a7;8;ls)m4?SLIRQ1^JH-ExSozw$aaX&*&KX zoTYhWUM-{Rl<=d`kzg=*0gGQ_SFQl?0qUmt5%vr1D3XV8bwfkLZu*|`zXfIhF#9vd zBz>!?+sEVJ!Av8lIcKuGb@Z`M3ll7Ub<6gtBr$jfY~L|=p^vCLh->?w$rX)NMc z$Q*+UUP!pzNS*a>UdVC)!hn9p>%$&CX2}26I3L>0vBl2+2i7X1yG2=PGXMYp07*qo IM6N<$f-=x1%m4rY literal 0 HcmV?d00001 diff --git a/Examples/Examples/Assets.xcassets/attachment.imageset/attachment@2x.png b/Examples/Examples/Assets.xcassets/attachment.imageset/attachment@2x.png new file mode 100644 index 0000000000000000000000000000000000000000..753fd95080067ad5d943e659b6078ed104d0ee2d GIT binary patch literal 3508 zcmV;l4NLNgP)Px?Zb?KzRCodHoePXrM;UR0{q9nRB zw#3p9aCwP5#1eE9(bS;UrfIDeR9+1=u?wgmv|6c1BWyM2ks{F zY+kr<;UTYi)6*3JrAY*B8CX$KF(2VRfRL|Ei_Z3PQ%6U~{KbnG@Aq3k5l~8Efaz0S zUj7hJ<`PuxSCDS$0p3ZPC)(TFzd>Dx-O{W0A|NEOeEISTI6nuD%q>wL7dksTn-(ov z)a<3AUJq!+iWQ9r>ie7(UIZ3a8Z_#0v}q>VbkV8IUJD4pFrt+=qcsmY2`I`qAnl_5 zh6M{2wA$+Fm4If?p8d{2g9dFtIFoFGF@zsSpj$Y9kI8-H(xppBF(!`VR?E!?C zS@Pas$ZrceOc@{LhB;zN(CYvRoWX+!Z$=oOGzmlx1BOiOPcdga%DD$2%C+mUY}vB+ zl4u&R9>%S7&5%gE2&4&=e?C2JuL9%~&a*O^V;b*E7n;{=1U{HybOGtViiTa|lJ92> zb<@(*^cp}u;9NjR_am&w(}k7o_0pwFZ$z6m0_ojOWuUQ5Jk)+$Ptz*^`GC{P1La+4 z%^!6kh2h6qtO3BUfHdBrybgxC51@Iks5GU@Q>d;FI0q5VhogWavK31Wv$_uN4hLD6 zF(iIVk1uEq@&kvvyO!bQO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View listen to font changes for all buttons --- MessageViewController/MessageView.swift | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/MessageViewController/MessageView.swift b/MessageViewController/MessageView.swift index cb82a07..481f1a2 100644 --- a/MessageViewController/MessageView.swift +++ b/MessageViewController/MessageView.swift @@ -20,14 +20,7 @@ public final class MessageView: UIView, MessageTextViewListener { internal var contentView: UIView? internal var leftButtonAction: Selector? internal var rightButtonAction: Selector? - public var showLeftButton: Bool = true { - didSet { - if !showLeftButton { - leftButton.removeFromSuperview() - setNeedsLayout() - } - } - } + public var showLeftButton: Bool = true public enum buttonType { case left @@ -39,9 +32,7 @@ public final class MessageView: UIView, MessageTextViewListener { backgroundColor = .white - if showLeftButton { - addSubview(leftButton) - } + addSubview(leftButton) addSubview(textView) addSubview(rightButton) layer.addSublayer(topBorderLayer) @@ -96,6 +87,8 @@ public final class MessageView: UIView, MessageTextViewListener { public var font: UIFont? { get { return textView.font } set { + leftButton.titleLabel?.font = newValue + rightButton.titleLabel?.font = newValue textView.font = newValue delegate?.wantsLayout(messageView: self) } From 7dbc585de92628028d576f24d992e3c2a44fd573 Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 16:07:00 +0100 Subject: [PATCH 5/8] Set preferred font size --- Examples/Examples/ViewController.swift | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Examples/Examples/ViewController.swift b/Examples/Examples/ViewController.swift index 10ff4b5..050864d 100644 --- a/Examples/Examples/ViewController.swift +++ b/Examples/Examples/ViewController.swift @@ -24,18 +24,18 @@ class ViewController: MessageViewController, UITableViewDataSource, UITableViewD view.addSubview(tableView) borderColor = .lightGray - + + messageView.inset = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 16) + messageView.font = UIFont.preferredFont(forTextStyle: .body) messageView.buttonLeftInset = 8 messageView.set(buttonIcon: UIImage(named: "attachment"), for: .normal, type: .left) messageView.addButton(target: self, action: #selector(onLeftButton), type: .left) messageView.showLeftButton = true - messageView.inset = UIEdgeInsets(top: 8, left: 8, bottom: 8, right: 16) messageView.textView.placeholderText = "New message..." messageView.textView.placeholderTextColor = .lightGray messageView.textView.backgroundColor = .white - messageView.font = UIFont.preferredFont(forTextStyle: .body) messageView.set(buttonTitle: "Send", for: .normal, type: .right) messageView.addButton(target: self, action: #selector(onRightButton), type: .right) From edc2e1185b04d607e871fdf523d9b283e54c61b9 Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 16:40:42 +0100 Subject: [PATCH 6/8] Version bump --- MessageViewController.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MessageViewController.podspec b/MessageViewController.podspec index c5aadc0..77ff34b 100644 --- a/MessageViewController.podspec +++ b/MessageViewController.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |spec| spec.name = 'MessageViewController' - spec.version = '0.1.1' + spec.version = '0.1.2' spec.license = { :type => 'MIT' } spec.homepage = 'https://github.com/GitHawkApp/MessageViewController' spec.authors = { 'Ryan Nystrom' => 'rnystrom@whoisryannystrom.com' } From 0abeddce13b05a74f8394807f95269d86aa607c0 Mon Sep 17 00:00:00 2001 From: Leon Keijzer Date: Thu, 22 Feb 2018 16:51:49 +0100 Subject: [PATCH 7/8] remove project files --- Examples/.idea/Examples.iml | 2 - Examples/.idea/codeStyles/Project.xml | 32 --- Examples/.idea/modules.xml | 8 - Examples/.idea/vcs.xml | 6 - Examples/.idea/workspace.xml | 268 -------------------------- Examples/.idea/xcode.xml | 4 - 6 files changed, 320 deletions(-) delete mode 100644 Examples/.idea/Examples.iml delete mode 100644 Examples/.idea/codeStyles/Project.xml delete mode 100644 Examples/.idea/modules.xml delete mode 100644 Examples/.idea/vcs.xml delete mode 100644 Examples/.idea/workspace.xml delete mode 100644 Examples/.idea/xcode.xml diff --git a/Examples/.idea/Examples.iml b/Examples/.idea/Examples.iml deleted file mode 100644 index 74121dc..0000000 --- a/Examples/.idea/Examples.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Examples/.idea/codeStyles/Project.xml b/Examples/.idea/codeStyles/Project.xml deleted file mode 100644 index 45f86bc..0000000 --- a/Examples/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Examples/.idea/modules.xml b/Examples/.idea/modules.xml deleted file mode 100644 index 485bd42..0000000 --- a/Examples/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Examples/.idea/vcs.xml b/Examples/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Examples/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Examples/.idea/workspace.xml b/Examples/.idea/workspace.xml deleted file mode 100644 index 99b41fd..0000000 --- a/Examples/.idea/workspace.xml +++ /dev/null @@ -1,268 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - button - addButton - buttonLeftInset - setLeft - - - rightButton - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 1519295978388 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/xcode.xml b/.idea/xcode.xml deleted file mode 100644 index 7a02f9e..0000000 --- a/.idea/xcode.xml +++ /dev/null @@ -1,4 +0,0 @@ - - - - \ No newline at end of file diff --git a/Examples/.idea/Examples.iml b/Examples/.idea/Examples.iml deleted file mode 100644 index 74121dc..0000000 --- a/Examples/.idea/Examples.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/Examples/.idea/codeStyles/Project.xml b/Examples/.idea/codeStyles/Project.xml deleted file mode 100644 index 45f86bc..0000000 --- a/Examples/.idea/codeStyles/Project.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/Examples/.idea/modules.xml b/Examples/.idea/modules.xml deleted file mode 100644 index 485bd42..0000000 --- a/Examples/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/Examples/.idea/vcs.xml b/Examples/.idea/vcs.xml deleted file mode 100644 index 6c0b863..0000000 --- a/Examples/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/Examples/.idea/workspace.xml b/Examples/.idea/workspace.xml deleted file mode 100644 index 99b41fd..0000000 --- a/Examples/.idea/workspace.xml +++ /dev/null @@ -1,268 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - button - addButton - buttonLeftInset - setLeft - - - rightButton - - - - - - - - - - - true - DEFINITION_ORDER - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -