├── .gitignore ├── ButtonStyleKit.podspec ├── ButtonStyleKitSample ├── ButtonStyleKit │ ├── ButtonStyleBuilder.swift │ ├── ButtonStyleKit.h │ ├── ButtonStyleKit.swift │ ├── ButtonStyleSelectableBase.swift │ ├── ButtonStyleStandardBase.swift │ └── Info.plist ├── ButtonStyleKitSample.xcodeproj │ ├── project.pbxproj │ ├── project.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ │ └── IDEWorkspaceChecks.plist │ └── xcshareddata │ │ └── xcschemes │ │ ├── ButtonStyleKit.xcscheme │ │ └── ButtonStyleKitSample.xcscheme ├── ButtonStyleKitSample │ ├── AppDelegate.swift │ ├── Assets.xcassets │ │ └── AppIcon.appiconset │ │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── ButtonStyle │ │ ├── ButtonGroupHelper.swift │ │ ├── SampleButtonCheckboxStyle.swift │ │ ├── SampleButtonRadioStyle.swift │ │ ├── SampleButtonShadowStyle.swift │ │ ├── SampleButtonStandardStyle.swift │ │ └── images.xcassets │ │ │ ├── Contents.json │ │ │ ├── checkbox.imageset │ │ │ ├── Contents.json │ │ │ ├── checkbox@2x.png │ │ │ └── checkbox@3x.png │ │ │ ├── checkbox_off.imageset │ │ │ ├── Contents.json │ │ │ ├── checkbox_off@2x.png │ │ │ └── checkbox_off@3x.png │ │ │ ├── checkbox_on.imageset │ │ │ ├── Contents.json │ │ │ ├── checkbox_on@2x.png │ │ │ └── checkbox_on@3x.png │ │ │ ├── radio.imageset │ │ │ ├── Contents.json │ │ │ ├── radio@2x.png │ │ │ └── radio@3x.png │ │ │ ├── radio_off.imageset │ │ │ ├── Contents.json │ │ │ ├── radio_off@2x.png │ │ │ └── radio_off@3x.png │ │ │ └── radio_on.imageset │ │ │ ├── Contents.json │ │ │ ├── radio_on@2x.png │ │ │ └── radio_on@3x.png │ ├── Info.plist │ └── ViewController.swift └── images │ ├── button.afdesign │ ├── checkbox@2x.png │ ├── checkbox@3x.png │ ├── checkbox_off@2x.png │ ├── checkbox_off@3x.png │ ├── checkbox_on@2x.png │ ├── checkbox_on@3x.png │ ├── radio@2x.png │ ├── radio@3x.png │ ├── radio_off@2x.png │ ├── radio_off@3x.png │ ├── radio_on@2x.png │ ├── radio_on@3x.png │ └── readme │ ├── StandardStyle.afdesign │ ├── StandardStyle.png │ ├── button_disabled.png │ ├── button_highlighted.png │ ├── button_normal.png │ ├── screen.afdesign │ ├── screen.png │ ├── screen01.png │ ├── screen02.png │ └── xcode.afdesign ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Swift ### 4 | # Xcode 5 | # 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | *.xccheckout 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | *.xcuserstate 22 | 23 | # CocoaPods 24 | # 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | Pods/ 30 | 31 | # Carthage 32 | # 33 | # Add this line if you want to avoid checking in source code from Carthage dependencies. 34 | # 35 | Carthage/ 36 | 37 | -------------------------------------------------------------------------------- /ButtonStyleKit.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = "ButtonStyleKit" 3 | s.version = "1.6.0" 4 | s.summary = "ButtonStyleKit is helper library for UIButton custom styles." 5 | s.homepage = "https://github.com/keygx/ButtonStyleKit" 6 | s.license = { :type => "MIT", :file => "LICENSE" } 7 | s.author = { "keygx" => "y.kagiyama@gmail.com" } 8 | s.social_media_url = "http://twitter.com/keygx" 9 | s.platform = :ios 10 | s.ios.deployment_target = '9.0' 11 | s.source = { :git => "https://github.com/keygx/GradientCircularProgress.git", :tag => "#{s.version}" } 12 | s.source_files = "ButtonStyleKitSample/ButtonStyleKit/*.{h,swift}" 13 | s.requires_arc = true 14 | end 15 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/ButtonStyleBuilder.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonStyleBuilder.swift 3 | // ButtonStyleKit 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | private class Property { 12 | var normal: T? 13 | var highlighted: T? 14 | var selected: T? 15 | var disabled: T? 16 | } 17 | 18 | open class ButtonStyleBuilder { 19 | // Basic 20 | private weak var button: ButtonStyleKit! 21 | private var state: ButtonStyleKit.ButtonState = .normal 22 | // Styles 23 | private var font = Property() 24 | private var borderWidth = Property() 25 | private var borderColor = Property() 26 | private var cornerRadius = Property() 27 | private var opacity = Property() 28 | private var backgroundColor = Property() 29 | private var tintColor = Property() 30 | private var shadowColor = Property() 31 | private var shadowOpacity = Property() 32 | private var shadowOffset = Property() 33 | private var shadowRadius = Property() 34 | private var shadowPath = Property() 35 | private var clipsToBounds = Property() 36 | private var masksToBounds = Property() 37 | private var isExclusiveTouch = Property() 38 | private var contentHorizontalAlignment = Property() 39 | private var contentVerticalAlignment = Property() 40 | private var titleEdgeInsets = Property() 41 | private var contentEdgeInsets = Property() 42 | private var imageEdgeInsets = Property() 43 | private var reversesTitleShadowWhenHighlighted = Property() 44 | private var adjustsImageWhenHighlighted = Property() 45 | private var adjustsImageWhenDisabled = Property() 46 | private var showsTouchWhenHighlighted = Property() 47 | 48 | public init() {} 49 | 50 | // Chain 51 | public func setButton(_ button: ButtonStyleKit) -> Self { 52 | self.button = button 53 | return self 54 | } 55 | 56 | public func setState(_ state: ButtonStyleKit.ButtonState) -> Self { 57 | self.state = state 58 | return self 59 | } 60 | 61 | public func setTitle(_ title: String) -> Self { 62 | if let state = state.getState() { 63 | button.setTitle(title, for: state) 64 | } else { 65 | button.setTitle(title, for: .normal) 66 | button.setTitle(title, for: .highlighted) 67 | button.setTitle(title, for: .selected) 68 | button.setTitle(title, for: .disabled) 69 | } 70 | return self 71 | } 72 | 73 | public func setTitleColor(_ titleColor: UIColor) -> Self { 74 | if let state = state.getState() { 75 | button.setTitleColor(titleColor, for: state) 76 | } else { 77 | button.setTitleColor(titleColor, for: .normal) 78 | button.setTitleColor(titleColor, for: .highlighted) 79 | button.setTitleColor(titleColor, for: .selected) 80 | button.setTitleColor(titleColor, for: .disabled) 81 | } 82 | return self 83 | } 84 | 85 | public func setTitleShadowColor(_ titleShadowColor: UIColor) -> Self { 86 | if let state = state.getState() { 87 | button.setTitleShadowColor(titleShadowColor, for: state) 88 | } else { 89 | button.setTitleShadowColor(titleShadowColor, for: .normal) 90 | button.setTitleShadowColor(titleShadowColor, for: .highlighted) 91 | button.setTitleShadowColor(titleShadowColor, for: .selected) 92 | button.setTitleShadowColor(titleShadowColor, for: .disabled) 93 | } 94 | return self 95 | } 96 | 97 | public func setImage(_ image: UIImage) -> Self { 98 | if let state = state.getState() { 99 | button.setImage(image, for: state) 100 | } else { 101 | button.setImage(image, for: .normal) 102 | button.setImage(image, for: .highlighted) 103 | button.setImage(image, for: .selected) 104 | button.setImage(image, for: .disabled) 105 | } 106 | return self 107 | } 108 | 109 | public func setBackgroundImage(_ backgroundImage: UIImage) -> Self { 110 | if let state = state.getState() { 111 | button.setBackgroundImage(backgroundImage, for: state) 112 | } else { 113 | button.setBackgroundImage(backgroundImage, for: .normal) 114 | button.setBackgroundImage(backgroundImage, for: .highlighted) 115 | button.setBackgroundImage(backgroundImage, for: .selected) 116 | button.setBackgroundImage(backgroundImage, for: .disabled) 117 | } 118 | return self 119 | } 120 | 121 | public func setAttributedTitle(_ attributedTitle: NSAttributedString) -> Self { 122 | if let state = state.getState() { 123 | button.setAttributedTitle(attributedTitle, for: state) 124 | } else { 125 | button.setAttributedTitle(attributedTitle, for: .normal) 126 | button.setAttributedTitle(attributedTitle, for: .highlighted) 127 | button.setAttributedTitle(attributedTitle, for: .selected) 128 | button.setAttributedTitle(attributedTitle, for: .disabled) 129 | } 130 | return self 131 | } 132 | 133 | public func setFont(_ font: UIFont) -> Self { 134 | setProperty(param: self.font, value: font, state: state) 135 | return self 136 | } 137 | 138 | public func setBorderWidth(_ borderWidth: CGFloat) -> Self { 139 | setProperty(param: self.borderWidth, value: borderWidth, state: state) 140 | return self 141 | } 142 | 143 | public func setBorderColor(_ borderColor: UIColor) -> Self { 144 | setProperty(param: self.borderColor, value: borderColor, state: state) 145 | return self 146 | } 147 | 148 | public func setCornerRadius(_ cornerRadius: CGFloat) -> Self { 149 | setProperty(param: self.cornerRadius, value: cornerRadius, state: state) 150 | return self 151 | } 152 | 153 | public func setOpacity(_ opacity: Float) -> Self { 154 | setProperty(param: self.opacity, value: opacity, state: state) 155 | return self 156 | } 157 | 158 | public func setBackgroundColor(_ backgroundColor: UIColor) -> Self { 159 | setProperty(param: self.backgroundColor, value: backgroundColor, state: state) 160 | return self 161 | } 162 | 163 | public func setTintColor(_ tintColor: UIColor) -> Self { 164 | setProperty(param: self.tintColor, value: tintColor, state: state) 165 | return self 166 | } 167 | 168 | public func setShadowColor(_ shadowColor: UIColor) -> Self { 169 | setProperty(param: self.shadowColor, value: shadowColor, state: state) 170 | return self 171 | } 172 | 173 | public func setShadowOpacity(_ shadowOpacity: Float) -> Self { 174 | setProperty(param: self.shadowOpacity, value: shadowOpacity, state: state) 175 | return self 176 | } 177 | 178 | public func setShadowOffset(_ shadowOffset: CGSize) -> Self { 179 | setProperty(param: self.shadowOffset, value: shadowOffset, state: state) 180 | return self 181 | } 182 | 183 | public func setShadowRadius(_ shadowRadius: CGFloat) -> Self { 184 | setProperty(param: self.shadowRadius, value: shadowRadius, state: state) 185 | return self 186 | } 187 | 188 | public func setShadowPath(_ shadowPath: CGPath) -> Self { 189 | setProperty(param: self.shadowPath, value: shadowPath, state: state) 190 | return self 191 | } 192 | 193 | public func setMasksToBounds(_ masksToBounds: Bool) -> Self { 194 | setProperty(param: self.masksToBounds, value: masksToBounds, state: state) 195 | return self 196 | } 197 | 198 | public func setClipsToBounds(_ clipsToBounds: Bool) -> Self { 199 | setProperty(param: self.clipsToBounds, value: clipsToBounds, state: state) 200 | return self 201 | } 202 | 203 | public func setExclusiveTouch(_ isExclusiveTouch: Bool) -> Self { 204 | setProperty(param: self.isExclusiveTouch, value: isExclusiveTouch, state: state) 205 | return self 206 | } 207 | 208 | public func setContentHorizontalAlignment(_ contentHorizontalAlignment: UIControl.ContentHorizontalAlignment) -> Self { 209 | setProperty(param: self.contentHorizontalAlignment, value: contentHorizontalAlignment, state: state) 210 | return self 211 | } 212 | 213 | public func setContentVerticalAlignment(_ contentVerticalAlignment: UIControl.ContentVerticalAlignment) -> Self { 214 | setProperty(param: self.contentVerticalAlignment, value: contentVerticalAlignment, state: state) 215 | return self 216 | } 217 | 218 | public func setTitleEdgeInsets(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) -> Self { 219 | setProperty(param: self.titleEdgeInsets, value: UIEdgeInsets(top: top, left: left, bottom: bottom, right: right), state: state) 220 | return self 221 | } 222 | 223 | public func setContentEdgeInsets(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) -> Self { 224 | setProperty(param: self.contentEdgeInsets, value: UIEdgeInsets(top: top, left: left, bottom: bottom, right: right), state: state) 225 | return self 226 | } 227 | 228 | public func setImageEdgeInsets(top: CGFloat, right: CGFloat, bottom: CGFloat, left: CGFloat) -> Self { 229 | setProperty(param: self.imageEdgeInsets, value: UIEdgeInsets(top: top, left: left, bottom: bottom, right: right), state: state) 230 | return self 231 | } 232 | 233 | public func setReversesTitleShadowWhenHighlighted(_ bool: Bool) -> Self { 234 | setProperty(param: self.reversesTitleShadowWhenHighlighted, value: bool, state: state) 235 | return self 236 | } 237 | 238 | public func setAdjustsImageWhenHighlighted(_ bool: Bool) -> Self { 239 | setProperty(param: self.adjustsImageWhenHighlighted, value: bool, state: state) 240 | return self 241 | } 242 | 243 | public func setAdjustsImageWhenDisabled(_ bool: Bool) -> Self { 244 | setProperty(param: self.adjustsImageWhenDisabled, value: bool, state: state) 245 | return self 246 | } 247 | 248 | public func setShowsTouchWhenHighlighted(_ bool: Bool) -> Self { 249 | setProperty(param: self.showsTouchWhenHighlighted, value: bool, state: state) 250 | return self 251 | } 252 | 253 | private func setProperty(param: Property, value: T, state: ButtonStyleKit.ButtonState) { 254 | switch state { 255 | case .all: 256 | param.normal = value 257 | param.highlighted = value 258 | param.selected = value 259 | param.disabled = value 260 | case .normal: 261 | param.normal = value 262 | case .highlighted: 263 | param.highlighted = value 264 | case .selected: 265 | param.selected = value 266 | case .disabled: 267 | param.disabled = value 268 | } 269 | } 270 | 271 | // Appear 272 | public func build() { 273 | if let font = attachProperty(font, state: state) { 274 | button.titleLabel?.font = font 275 | } 276 | 277 | if let borderWidth = attachProperty(borderWidth, state: state) { 278 | button.layer.borderWidth = borderWidth 279 | } 280 | 281 | if let borderColor = attachProperty(borderColor, state: state) { 282 | button.layer.borderColor = borderColor.cgColor 283 | } 284 | 285 | if let cornerRadius = attachProperty(cornerRadius, state: state) { 286 | button.layer.cornerRadius = cornerRadius 287 | } 288 | 289 | if let opacity = attachProperty(opacity, state: state) { 290 | button.layer.opacity = opacity 291 | } 292 | 293 | if let backgroundColor = attachProperty(backgroundColor, state: state) { 294 | button.layer.backgroundColor = backgroundColor.cgColor 295 | } 296 | 297 | if let tintColor = attachProperty(tintColor, state: state) { 298 | button.tintColor = tintColor 299 | } 300 | 301 | if let shadowColor = attachProperty(shadowColor, state: state) { 302 | button.layer.shadowColor = shadowColor.cgColor 303 | } 304 | 305 | if let shadowOpacity = attachProperty(shadowOpacity, state: state) { 306 | button.layer.shadowOpacity = shadowOpacity 307 | } 308 | 309 | if let shadowOffset = attachProperty(shadowOffset, state: state) { 310 | button.layer.shadowOffset = shadowOffset 311 | } 312 | 313 | if let shadowRadius = attachProperty(shadowRadius, state: state) { 314 | button.layer.shadowRadius = shadowRadius 315 | } 316 | 317 | if let shadowPath = attachProperty(shadowPath, state: state) { 318 | button.layer.shadowPath = shadowPath 319 | } 320 | 321 | if let clipsToBounds = attachProperty(clipsToBounds, state: state) { 322 | button.clipsToBounds = clipsToBounds 323 | } 324 | 325 | if let masksToBounds = attachProperty(masksToBounds, state: state) { 326 | button.layer.masksToBounds = masksToBounds 327 | } 328 | 329 | if let isExclusiveTouch = attachProperty(isExclusiveTouch, state: state) { 330 | button.isExclusiveTouch = isExclusiveTouch 331 | } 332 | 333 | if let contentHorizontalAlignment = attachProperty(contentHorizontalAlignment, state: state) { 334 | button.contentHorizontalAlignment = contentHorizontalAlignment 335 | } 336 | 337 | if let contentVerticalAlignment = attachProperty(contentVerticalAlignment, state: state) { 338 | button.contentVerticalAlignment = contentVerticalAlignment 339 | } 340 | 341 | if let titleEdgeInsets = attachProperty(titleEdgeInsets, state: state) { 342 | button.titleEdgeInsets = titleEdgeInsets 343 | } 344 | 345 | if let contentEdgeInsets = attachProperty(contentEdgeInsets, state: state) { 346 | button.contentEdgeInsets = contentEdgeInsets 347 | } 348 | 349 | if let imageEdgeInsets = attachProperty(imageEdgeInsets, state: state) { 350 | button.imageEdgeInsets = imageEdgeInsets 351 | } 352 | 353 | if let reversesTitleShadowWhenHighlighted = attachProperty(reversesTitleShadowWhenHighlighted, state: state) { 354 | button.reversesTitleShadowWhenHighlighted = reversesTitleShadowWhenHighlighted 355 | } 356 | 357 | if let adjustsImageWhenHighlighted = attachProperty(adjustsImageWhenHighlighted, state: state) { 358 | button.adjustsImageWhenHighlighted = adjustsImageWhenHighlighted 359 | } 360 | 361 | if let adjustsImageWhenDisabled = attachProperty(adjustsImageWhenDisabled, state: state) { 362 | button.adjustsImageWhenDisabled = adjustsImageWhenDisabled 363 | } 364 | 365 | if let showsTouchWhenHighlighted = attachProperty(showsTouchWhenHighlighted, state: state) { 366 | button.showsTouchWhenHighlighted = showsTouchWhenHighlighted 367 | } 368 | } 369 | 370 | public func apply() { 371 | guard let button = button else { return } 372 | self.state = button.currentState 373 | build() 374 | } 375 | 376 | private func attachProperty(_ prop: Property, state: ButtonStyleKit.ButtonState) -> T? { 377 | switch state { 378 | case .all: 379 | return nil 380 | case .normal: 381 | return prop.normal 382 | case .highlighted: 383 | return prop.highlighted 384 | case .selected: 385 | return prop.selected 386 | case .disabled: 387 | return prop.disabled 388 | } 389 | } 390 | } 391 | 392 | // Helpers 393 | extension ButtonStyleBuilder { 394 | 395 | public final func createViewToImage(color: UIColor, frame: CGRect? = nil) -> UIImage? { 396 | // View 397 | var rect = CGRect() 398 | rect = { 399 | if let f = frame { 400 | return f 401 | } else { 402 | return CGRect(x: 0, y: 0, width: 100, height: 100) 403 | } 404 | }() 405 | 406 | let view = UIView(frame: rect) 407 | view.backgroundColor = color 408 | // Image 409 | let scale = UIScreen.main.scale 410 | UIGraphicsBeginImageContextWithOptions(view.frame.size, false, scale) 411 | guard let context = UIGraphicsGetCurrentContext() else { return nil } 412 | view.layer.render(in: context) 413 | let image = UIGraphicsGetImageFromCurrentImageContext() 414 | UIGraphicsEndImageContext() 415 | 416 | return image 417 | } 418 | 419 | public final func createImageView(frame: CGRect, normal: String, highlighted: String?) -> UIImageView { 420 | let imageView = UIImageView(frame: frame) 421 | imageView.image = UIImage(named: normal) 422 | if let highlighted = highlighted { 423 | imageView.highlightedImage = UIImage(named: highlighted) 424 | } 425 | imageView.contentMode = .scaleAspectFit 426 | 427 | return imageView 428 | } 429 | 430 | public final func createImageView(frame: CGRect, normal: UIImage, highlighted: UIImage?) -> UIImageView { 431 | let imageView = UIImageView(frame: frame) 432 | imageView.image = normal 433 | if let highlighted = highlighted { 434 | imageView.highlightedImage = highlighted 435 | } 436 | imageView.contentMode = .scaleAspectFit 437 | 438 | return imageView 439 | } 440 | } 441 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/ButtonStyleKit.h: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonStyleKit.h 3 | // ButtonStyleKit 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | //! Project version number for ButtonStyleKit. 12 | FOUNDATION_EXPORT double ButtonStyleKitVersionNumber; 13 | 14 | //! Project version string for ButtonStyleKit. 15 | FOUNDATION_EXPORT const unsigned char ButtonStyleKitVersionString[]; 16 | 17 | // In this header, you should import all the public headers of your framework using statements like #import 18 | 19 | 20 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/ButtonStyleKit.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonStyleKit.swift 3 | // ButtonStyleKit 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class ButtonStyleKit: UIButton { 12 | 13 | public enum ButtonState: Int { 14 | case all 15 | case normal 16 | case highlighted 17 | case selected 18 | case disabled 19 | 20 | func getState() -> UIControl.State? { 21 | switch self { 22 | case .all: 23 | return nil 24 | case .normal: 25 | return UIControl.State.normal 26 | case .highlighted: 27 | return UIControl.State.highlighted 28 | case .selected: 29 | return UIControl.State.selected 30 | case .disabled: 31 | return UIControl.State.disabled 32 | } 33 | } 34 | } 35 | 36 | open var currentState: ButtonState = .normal { 37 | didSet { 38 | switch currentState { 39 | case .all: 40 | break 41 | case .normal: 42 | super.isEnabled = true 43 | super.isHighlighted = false 44 | super.isSelected = false 45 | 46 | case .highlighted: 47 | super.isEnabled = true 48 | super.isHighlighted = true 49 | super.isSelected = false 50 | 51 | case .selected: 52 | super.isEnabled = true 53 | super.isHighlighted = false 54 | super.isSelected = true 55 | 56 | case .disabled: 57 | super.isEnabled = false 58 | super.isHighlighted = false 59 | super.isSelected = false 60 | } 61 | } 62 | } 63 | 64 | private var clickHandler: ((ButtonStyleKit) -> Void)? 65 | 66 | // init 67 | override init(frame: CGRect) { 68 | super.init(frame: frame) 69 | 70 | initialize() 71 | } 72 | 73 | required public init?(coder aDecoder: NSCoder) { 74 | super.init(coder: aDecoder) 75 | 76 | initialize() 77 | } 78 | 79 | private func initialize() { 80 | adjustsImageWhenHighlighted = false 81 | adjustsImageWhenDisabled = false 82 | showsTouchWhenHighlighted = false 83 | addTarget(self, action: #selector(ButtonStyleKit.didTapped(_:)), for: .touchUpInside) 84 | currentState = .normal 85 | 86 | initializedTrigger() 87 | } 88 | 89 | open func initializedTrigger() {} 90 | 91 | // Event Handling 92 | @objc private func didTapped(_ sender: UIButton) { 93 | if let clickHandler = clickHandler { 94 | clickHandler(self) 95 | } 96 | } 97 | 98 | public final func setClickHandler(handler: @escaping ((ButtonStyleKit) -> Void)) { 99 | clickHandler = handler 100 | } 101 | } 102 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/ButtonStyleSelectableBase.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonStyleSelectableBase.swift 3 | // ButtonStyleKit 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class ButtonStyleSelectableBase: ButtonStyleKit { 12 | 13 | override public final var isEnabled: Bool { 14 | set { 15 | if newValue { 16 | currentState = .normal 17 | } else { 18 | currentState = .disabled 19 | } 20 | } 21 | get { 22 | return super.isEnabled 23 | } 24 | } 25 | 26 | override public final var isSelected: Bool { 27 | set { 28 | if newValue { 29 | value = true 30 | } else { 31 | value = false 32 | } 33 | } 34 | get { 35 | return super.isSelected 36 | } 37 | } 38 | 39 | public final var value: Bool = false { 40 | didSet { 41 | currentState = { 42 | if value { 43 | return .selected 44 | } else { 45 | return .normal 46 | } 47 | }() 48 | } 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/ButtonStyleStandardBase.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonStyleStandardBase.swift 3 | // ButtonStyleKit 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | open class ButtonStyleStandardBase: ButtonStyleKit { 12 | 13 | override public final var isEnabled: Bool { 14 | set { 15 | if newValue { 16 | currentState = .normal 17 | } else { 18 | currentState = .disabled 19 | } 20 | } 21 | get { 22 | return super.isEnabled 23 | } 24 | } 25 | 26 | override public final var isHighlighted: Bool { 27 | set { 28 | if newValue { 29 | currentState = .highlighted 30 | } else { 31 | currentState = .normal 32 | } 33 | } 34 | get { 35 | return super.isHighlighted 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKit/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | FMWK 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | NSPrincipalClass 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 367CA85E1D71612100E6ABC3 /* ButtonGroupHelper.swift in Sources */ = {isa = PBXBuildFile; fileRef = 367CA85D1D71612100E6ABC3 /* ButtonGroupHelper.swift */; }; 11 | 36AD61001D52609900752599 /* SampleButtonRadioStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36AD60FF1D52609900752599 /* SampleButtonRadioStyle.swift */; }; 12 | 36B537C11D33409B0037CA02 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B537C01D33409B0037CA02 /* AppDelegate.swift */; }; 13 | 36B537C31D33409B0037CA02 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B537C21D33409B0037CA02 /* ViewController.swift */; }; 14 | 36B537C61D33409B0037CA02 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36B537C41D33409B0037CA02 /* Main.storyboard */; }; 15 | 36B537C81D33409B0037CA02 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36B537C71D33409B0037CA02 /* Assets.xcassets */; }; 16 | 36B537CB1D33409B0037CA02 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 36B537C91D33409B0037CA02 /* LaunchScreen.storyboard */; }; 17 | 36B537DB1D3340CA0037CA02 /* ButtonStyleKit.h in Headers */ = {isa = PBXBuildFile; fileRef = 36B537D91D3340CA0037CA02 /* ButtonStyleKit.h */; settings = {ATTRIBUTES = (Public, ); }; }; 18 | 36B537DE1D3340CA0037CA02 /* ButtonStyleKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 36B537D71D3340C90037CA02 /* ButtonStyleKit.framework */; }; 19 | 36B537DF1D3340CA0037CA02 /* ButtonStyleKit.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 36B537D71D3340C90037CA02 /* ButtonStyleKit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; 20 | 36B537E51D3340F40037CA02 /* ButtonStyleKit.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B537E41D3340F40037CA02 /* ButtonStyleKit.swift */; }; 21 | 36B537E91D3344520037CA02 /* SampleButtonStandardStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B537E71D3344520037CA02 /* SampleButtonStandardStyle.swift */; }; 22 | 36B8B8021D336316003A8172 /* SampleButtonCheckboxStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36B8B8011D336316003A8172 /* SampleButtonCheckboxStyle.swift */; }; 23 | 36B8B8041D3367EF003A8172 /* images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 36B8B8031D3367EF003A8172 /* images.xcassets */; }; 24 | 36DAF3191D37CA530056A56F /* ButtonStyleBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36DAF3181D37CA530056A56F /* ButtonStyleBuilder.swift */; }; 25 | 36E99BC71D46149A001968D8 /* ButtonStyleSelectableBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E99BC61D46149A001968D8 /* ButtonStyleSelectableBase.swift */; }; 26 | 36E99BC91D461526001968D8 /* ButtonStyleStandardBase.swift in Sources */ = {isa = PBXBuildFile; fileRef = 36E99BC81D461526001968D8 /* ButtonStyleStandardBase.swift */; }; 27 | A9AC8F8C2154A170002675B9 /* SampleButtonShadowStyle.swift in Sources */ = {isa = PBXBuildFile; fileRef = A9AC8F8B2154A170002675B9 /* SampleButtonShadowStyle.swift */; }; 28 | /* End PBXBuildFile section */ 29 | 30 | /* Begin PBXContainerItemProxy section */ 31 | 36B537DC1D3340CA0037CA02 /* PBXContainerItemProxy */ = { 32 | isa = PBXContainerItemProxy; 33 | containerPortal = 36B537B51D33409B0037CA02 /* Project object */; 34 | proxyType = 1; 35 | remoteGlobalIDString = 36B537D61D3340C90037CA02; 36 | remoteInfo = ButtonStyleKit; 37 | }; 38 | /* End PBXContainerItemProxy section */ 39 | 40 | /* Begin PBXCopyFilesBuildPhase section */ 41 | 36B537E31D3340CA0037CA02 /* Embed Frameworks */ = { 42 | isa = PBXCopyFilesBuildPhase; 43 | buildActionMask = 2147483647; 44 | dstPath = ""; 45 | dstSubfolderSpec = 10; 46 | files = ( 47 | 36B537DF1D3340CA0037CA02 /* ButtonStyleKit.framework in Embed Frameworks */, 48 | ); 49 | name = "Embed Frameworks"; 50 | runOnlyForDeploymentPostprocessing = 0; 51 | }; 52 | /* End PBXCopyFilesBuildPhase section */ 53 | 54 | /* Begin PBXFileReference section */ 55 | 367CA85D1D71612100E6ABC3 /* ButtonGroupHelper.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonGroupHelper.swift; sourceTree = ""; }; 56 | 36AD60FF1D52609900752599 /* SampleButtonRadioStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleButtonRadioStyle.swift; sourceTree = ""; }; 57 | 36B537BD1D33409B0037CA02 /* ButtonStyleKitSample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = ButtonStyleKitSample.app; sourceTree = BUILT_PRODUCTS_DIR; }; 58 | 36B537C01D33409B0037CA02 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 59 | 36B537C21D33409B0037CA02 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 60 | 36B537C51D33409B0037CA02 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 61 | 36B537C71D33409B0037CA02 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 62 | 36B537CA1D33409B0037CA02 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 63 | 36B537CC1D33409B0037CA02 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 64 | 36B537D71D3340C90037CA02 /* ButtonStyleKit.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = ButtonStyleKit.framework; sourceTree = BUILT_PRODUCTS_DIR; }; 65 | 36B537D91D3340CA0037CA02 /* ButtonStyleKit.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ButtonStyleKit.h; sourceTree = ""; }; 66 | 36B537DA1D3340CA0037CA02 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 67 | 36B537E41D3340F40037CA02 /* ButtonStyleKit.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonStyleKit.swift; sourceTree = ""; }; 68 | 36B537E71D3344520037CA02 /* SampleButtonStandardStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleButtonStandardStyle.swift; sourceTree = ""; }; 69 | 36B8B8011D336316003A8172 /* SampleButtonCheckboxStyle.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SampleButtonCheckboxStyle.swift; sourceTree = ""; }; 70 | 36B8B8031D3367EF003A8172 /* images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = images.xcassets; sourceTree = ""; }; 71 | 36DAF3181D37CA530056A56F /* ButtonStyleBuilder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonStyleBuilder.swift; sourceTree = ""; }; 72 | 36E99BC61D46149A001968D8 /* ButtonStyleSelectableBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonStyleSelectableBase.swift; sourceTree = ""; }; 73 | 36E99BC81D461526001968D8 /* ButtonStyleStandardBase.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ButtonStyleStandardBase.swift; sourceTree = ""; }; 74 | A9AC8F8B2154A170002675B9 /* SampleButtonShadowStyle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SampleButtonShadowStyle.swift; sourceTree = ""; }; 75 | /* End PBXFileReference section */ 76 | 77 | /* Begin PBXFrameworksBuildPhase section */ 78 | 36B537BA1D33409B0037CA02 /* Frameworks */ = { 79 | isa = PBXFrameworksBuildPhase; 80 | buildActionMask = 2147483647; 81 | files = ( 82 | 36B537DE1D3340CA0037CA02 /* ButtonStyleKit.framework in Frameworks */, 83 | ); 84 | runOnlyForDeploymentPostprocessing = 0; 85 | }; 86 | 36B537D31D3340C90037CA02 /* Frameworks */ = { 87 | isa = PBXFrameworksBuildPhase; 88 | buildActionMask = 2147483647; 89 | files = ( 90 | ); 91 | runOnlyForDeploymentPostprocessing = 0; 92 | }; 93 | /* End PBXFrameworksBuildPhase section */ 94 | 95 | /* Begin PBXGroup section */ 96 | 36B537B41D33409B0037CA02 = { 97 | isa = PBXGroup; 98 | children = ( 99 | 36B537BF1D33409B0037CA02 /* ButtonStyleKitSample */, 100 | 36B537D81D3340CA0037CA02 /* ButtonStyleKit */, 101 | 36B537BE1D33409B0037CA02 /* Products */, 102 | ); 103 | sourceTree = ""; 104 | }; 105 | 36B537BE1D33409B0037CA02 /* Products */ = { 106 | isa = PBXGroup; 107 | children = ( 108 | 36B537BD1D33409B0037CA02 /* ButtonStyleKitSample.app */, 109 | 36B537D71D3340C90037CA02 /* ButtonStyleKit.framework */, 110 | ); 111 | name = Products; 112 | sourceTree = ""; 113 | }; 114 | 36B537BF1D33409B0037CA02 /* ButtonStyleKitSample */ = { 115 | isa = PBXGroup; 116 | children = ( 117 | 36B537E61D3344520037CA02 /* ButtonStyle */, 118 | 36B537C01D33409B0037CA02 /* AppDelegate.swift */, 119 | 36B537C21D33409B0037CA02 /* ViewController.swift */, 120 | 36B537C41D33409B0037CA02 /* Main.storyboard */, 121 | 36B537C71D33409B0037CA02 /* Assets.xcassets */, 122 | 36B537C91D33409B0037CA02 /* LaunchScreen.storyboard */, 123 | 36B537CC1D33409B0037CA02 /* Info.plist */, 124 | ); 125 | path = ButtonStyleKitSample; 126 | sourceTree = ""; 127 | }; 128 | 36B537D81D3340CA0037CA02 /* ButtonStyleKit */ = { 129 | isa = PBXGroup; 130 | children = ( 131 | 36B537D91D3340CA0037CA02 /* ButtonStyleKit.h */, 132 | 36B537DA1D3340CA0037CA02 /* Info.plist */, 133 | 36B537E41D3340F40037CA02 /* ButtonStyleKit.swift */, 134 | 36E99BC81D461526001968D8 /* ButtonStyleStandardBase.swift */, 135 | 36E99BC61D46149A001968D8 /* ButtonStyleSelectableBase.swift */, 136 | 36DAF3181D37CA530056A56F /* ButtonStyleBuilder.swift */, 137 | ); 138 | path = ButtonStyleKit; 139 | sourceTree = ""; 140 | }; 141 | 36B537E61D3344520037CA02 /* ButtonStyle */ = { 142 | isa = PBXGroup; 143 | children = ( 144 | 367CA85D1D71612100E6ABC3 /* ButtonGroupHelper.swift */, 145 | 36B537E71D3344520037CA02 /* SampleButtonStandardStyle.swift */, 146 | A9AC8F8B2154A170002675B9 /* SampleButtonShadowStyle.swift */, 147 | 36B8B8011D336316003A8172 /* SampleButtonCheckboxStyle.swift */, 148 | 36AD60FF1D52609900752599 /* SampleButtonRadioStyle.swift */, 149 | 36B8B8031D3367EF003A8172 /* images.xcassets */, 150 | ); 151 | path = ButtonStyle; 152 | sourceTree = ""; 153 | }; 154 | /* End PBXGroup section */ 155 | 156 | /* Begin PBXHeadersBuildPhase section */ 157 | 36B537D41D3340C90037CA02 /* Headers */ = { 158 | isa = PBXHeadersBuildPhase; 159 | buildActionMask = 2147483647; 160 | files = ( 161 | 36B537DB1D3340CA0037CA02 /* ButtonStyleKit.h in Headers */, 162 | ); 163 | runOnlyForDeploymentPostprocessing = 0; 164 | }; 165 | /* End PBXHeadersBuildPhase section */ 166 | 167 | /* Begin PBXNativeTarget section */ 168 | 36B537BC1D33409B0037CA02 /* ButtonStyleKitSample */ = { 169 | isa = PBXNativeTarget; 170 | buildConfigurationList = 36B537CF1D33409B0037CA02 /* Build configuration list for PBXNativeTarget "ButtonStyleKitSample" */; 171 | buildPhases = ( 172 | 36B537B91D33409B0037CA02 /* Sources */, 173 | 36B537BA1D33409B0037CA02 /* Frameworks */, 174 | 36B537BB1D33409B0037CA02 /* Resources */, 175 | 36B537E31D3340CA0037CA02 /* Embed Frameworks */, 176 | ); 177 | buildRules = ( 178 | ); 179 | dependencies = ( 180 | 36B537DD1D3340CA0037CA02 /* PBXTargetDependency */, 181 | ); 182 | name = ButtonStyleKitSample; 183 | productName = ButtonStyleKitSample; 184 | productReference = 36B537BD1D33409B0037CA02 /* ButtonStyleKitSample.app */; 185 | productType = "com.apple.product-type.application"; 186 | }; 187 | 36B537D61D3340C90037CA02 /* ButtonStyleKit */ = { 188 | isa = PBXNativeTarget; 189 | buildConfigurationList = 36B537E01D3340CA0037CA02 /* Build configuration list for PBXNativeTarget "ButtonStyleKit" */; 190 | buildPhases = ( 191 | 36B537D21D3340C90037CA02 /* Sources */, 192 | 36B537D31D3340C90037CA02 /* Frameworks */, 193 | 36B537D41D3340C90037CA02 /* Headers */, 194 | 36B537D51D3340C90037CA02 /* Resources */, 195 | ); 196 | buildRules = ( 197 | ); 198 | dependencies = ( 199 | ); 200 | name = ButtonStyleKit; 201 | productName = ButtonStyleKit; 202 | productReference = 36B537D71D3340C90037CA02 /* ButtonStyleKit.framework */; 203 | productType = "com.apple.product-type.framework"; 204 | }; 205 | /* End PBXNativeTarget section */ 206 | 207 | /* Begin PBXProject section */ 208 | 36B537B51D33409B0037CA02 /* Project object */ = { 209 | isa = PBXProject; 210 | attributes = { 211 | LastSwiftUpdateCheck = 0800; 212 | LastUpgradeCheck = 1230; 213 | ORGANIZATIONNAME = keygx; 214 | TargetAttributes = { 215 | 36B537BC1D33409B0037CA02 = { 216 | CreatedOnToolsVersion = 8.0; 217 | DevelopmentTeam = 3CCNMX7TC9; 218 | DevelopmentTeamName = "Yukihiko Kagiyama"; 219 | LastSwiftMigration = 1020; 220 | ProvisioningStyle = Automatic; 221 | }; 222 | 36B537D61D3340C90037CA02 = { 223 | CreatedOnToolsVersion = 8.0; 224 | DevelopmentTeam = 3CCNMX7TC9; 225 | DevelopmentTeamName = "Yukihiko Kagiyama"; 226 | LastSwiftMigration = 1020; 227 | ProvisioningStyle = Automatic; 228 | }; 229 | }; 230 | }; 231 | buildConfigurationList = 36B537B81D33409B0037CA02 /* Build configuration list for PBXProject "ButtonStyleKitSample" */; 232 | compatibilityVersion = "Xcode 3.2"; 233 | developmentRegion = en; 234 | hasScannedForEncodings = 0; 235 | knownRegions = ( 236 | en, 237 | Base, 238 | ); 239 | mainGroup = 36B537B41D33409B0037CA02; 240 | productRefGroup = 36B537BE1D33409B0037CA02 /* Products */; 241 | projectDirPath = ""; 242 | projectRoot = ""; 243 | targets = ( 244 | 36B537BC1D33409B0037CA02 /* ButtonStyleKitSample */, 245 | 36B537D61D3340C90037CA02 /* ButtonStyleKit */, 246 | ); 247 | }; 248 | /* End PBXProject section */ 249 | 250 | /* Begin PBXResourcesBuildPhase section */ 251 | 36B537BB1D33409B0037CA02 /* Resources */ = { 252 | isa = PBXResourcesBuildPhase; 253 | buildActionMask = 2147483647; 254 | files = ( 255 | 36B537CB1D33409B0037CA02 /* LaunchScreen.storyboard in Resources */, 256 | 36B8B8041D3367EF003A8172 /* images.xcassets in Resources */, 257 | 36B537C81D33409B0037CA02 /* Assets.xcassets in Resources */, 258 | 36B537C61D33409B0037CA02 /* Main.storyboard in Resources */, 259 | ); 260 | runOnlyForDeploymentPostprocessing = 0; 261 | }; 262 | 36B537D51D3340C90037CA02 /* Resources */ = { 263 | isa = PBXResourcesBuildPhase; 264 | buildActionMask = 2147483647; 265 | files = ( 266 | ); 267 | runOnlyForDeploymentPostprocessing = 0; 268 | }; 269 | /* End PBXResourcesBuildPhase section */ 270 | 271 | /* Begin PBXSourcesBuildPhase section */ 272 | 36B537B91D33409B0037CA02 /* Sources */ = { 273 | isa = PBXSourcesBuildPhase; 274 | buildActionMask = 2147483647; 275 | files = ( 276 | 36B537E91D3344520037CA02 /* SampleButtonStandardStyle.swift in Sources */, 277 | 367CA85E1D71612100E6ABC3 /* ButtonGroupHelper.swift in Sources */, 278 | 36B537C31D33409B0037CA02 /* ViewController.swift in Sources */, 279 | A9AC8F8C2154A170002675B9 /* SampleButtonShadowStyle.swift in Sources */, 280 | 36B8B8021D336316003A8172 /* SampleButtonCheckboxStyle.swift in Sources */, 281 | 36B537C11D33409B0037CA02 /* AppDelegate.swift in Sources */, 282 | 36AD61001D52609900752599 /* SampleButtonRadioStyle.swift in Sources */, 283 | ); 284 | runOnlyForDeploymentPostprocessing = 0; 285 | }; 286 | 36B537D21D3340C90037CA02 /* Sources */ = { 287 | isa = PBXSourcesBuildPhase; 288 | buildActionMask = 2147483647; 289 | files = ( 290 | 36E99BC91D461526001968D8 /* ButtonStyleStandardBase.swift in Sources */, 291 | 36B537E51D3340F40037CA02 /* ButtonStyleKit.swift in Sources */, 292 | 36E99BC71D46149A001968D8 /* ButtonStyleSelectableBase.swift in Sources */, 293 | 36DAF3191D37CA530056A56F /* ButtonStyleBuilder.swift in Sources */, 294 | ); 295 | runOnlyForDeploymentPostprocessing = 0; 296 | }; 297 | /* End PBXSourcesBuildPhase section */ 298 | 299 | /* Begin PBXTargetDependency section */ 300 | 36B537DD1D3340CA0037CA02 /* PBXTargetDependency */ = { 301 | isa = PBXTargetDependency; 302 | target = 36B537D61D3340C90037CA02 /* ButtonStyleKit */; 303 | targetProxy = 36B537DC1D3340CA0037CA02 /* PBXContainerItemProxy */; 304 | }; 305 | /* End PBXTargetDependency section */ 306 | 307 | /* Begin PBXVariantGroup section */ 308 | 36B537C41D33409B0037CA02 /* Main.storyboard */ = { 309 | isa = PBXVariantGroup; 310 | children = ( 311 | 36B537C51D33409B0037CA02 /* Base */, 312 | ); 313 | name = Main.storyboard; 314 | sourceTree = ""; 315 | }; 316 | 36B537C91D33409B0037CA02 /* LaunchScreen.storyboard */ = { 317 | isa = PBXVariantGroup; 318 | children = ( 319 | 36B537CA1D33409B0037CA02 /* Base */, 320 | ); 321 | name = LaunchScreen.storyboard; 322 | sourceTree = ""; 323 | }; 324 | /* End PBXVariantGroup section */ 325 | 326 | /* Begin XCBuildConfiguration section */ 327 | 36B537CD1D33409B0037CA02 /* Debug */ = { 328 | isa = XCBuildConfiguration; 329 | buildSettings = { 330 | ALWAYS_SEARCH_USER_PATHS = NO; 331 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 332 | CLANG_ANALYZER_NONNULL = YES; 333 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 334 | CLANG_CXX_LIBRARY = "libc++"; 335 | CLANG_ENABLE_MODULES = YES; 336 | CLANG_ENABLE_OBJC_ARC = YES; 337 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 338 | CLANG_WARN_BOOL_CONVERSION = YES; 339 | CLANG_WARN_COMMA = YES; 340 | CLANG_WARN_CONSTANT_CONVERSION = YES; 341 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 342 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 343 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 344 | CLANG_WARN_EMPTY_BODY = YES; 345 | CLANG_WARN_ENUM_CONVERSION = YES; 346 | CLANG_WARN_INFINITE_RECURSION = YES; 347 | CLANG_WARN_INT_CONVERSION = YES; 348 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 349 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 350 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 351 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 352 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 353 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 354 | CLANG_WARN_STRICT_PROTOTYPES = YES; 355 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 356 | CLANG_WARN_UNREACHABLE_CODE = YES; 357 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 358 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 359 | COPY_PHASE_STRIP = NO; 360 | DEBUG_INFORMATION_FORMAT = dwarf; 361 | ENABLE_STRICT_OBJC_MSGSEND = YES; 362 | ENABLE_TESTABILITY = YES; 363 | GCC_C_LANGUAGE_STANDARD = gnu99; 364 | GCC_DYNAMIC_NO_PIC = NO; 365 | GCC_NO_COMMON_BLOCKS = YES; 366 | GCC_OPTIMIZATION_LEVEL = 0; 367 | GCC_PREPROCESSOR_DEFINITIONS = ( 368 | "DEBUG=1", 369 | "$(inherited)", 370 | ); 371 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 372 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 373 | GCC_WARN_UNDECLARED_SELECTOR = YES; 374 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 375 | GCC_WARN_UNUSED_FUNCTION = YES; 376 | GCC_WARN_UNUSED_VARIABLE = YES; 377 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 378 | MTL_ENABLE_DEBUG_INFO = YES; 379 | ONLY_ACTIVE_ARCH = YES; 380 | SDKROOT = iphoneos; 381 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 382 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 383 | SWIFT_VERSION = ""; 384 | TARGETED_DEVICE_FAMILY = "1,2"; 385 | }; 386 | name = Debug; 387 | }; 388 | 36B537CE1D33409B0037CA02 /* Release */ = { 389 | isa = XCBuildConfiguration; 390 | buildSettings = { 391 | ALWAYS_SEARCH_USER_PATHS = NO; 392 | CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES; 393 | CLANG_ANALYZER_NONNULL = YES; 394 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 395 | CLANG_CXX_LIBRARY = "libc++"; 396 | CLANG_ENABLE_MODULES = YES; 397 | CLANG_ENABLE_OBJC_ARC = YES; 398 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 399 | CLANG_WARN_BOOL_CONVERSION = YES; 400 | CLANG_WARN_COMMA = YES; 401 | CLANG_WARN_CONSTANT_CONVERSION = YES; 402 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 403 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 404 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 405 | CLANG_WARN_EMPTY_BODY = YES; 406 | CLANG_WARN_ENUM_CONVERSION = YES; 407 | CLANG_WARN_INFINITE_RECURSION = YES; 408 | CLANG_WARN_INT_CONVERSION = YES; 409 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 410 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 411 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 412 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 413 | CLANG_WARN_QUOTED_INCLUDE_IN_FRAMEWORK_HEADER = YES; 414 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 415 | CLANG_WARN_STRICT_PROTOTYPES = YES; 416 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 417 | CLANG_WARN_UNREACHABLE_CODE = YES; 418 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 419 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 420 | COPY_PHASE_STRIP = NO; 421 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 422 | ENABLE_NS_ASSERTIONS = NO; 423 | ENABLE_STRICT_OBJC_MSGSEND = YES; 424 | GCC_C_LANGUAGE_STANDARD = gnu99; 425 | GCC_NO_COMMON_BLOCKS = YES; 426 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 427 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 428 | GCC_WARN_UNDECLARED_SELECTOR = YES; 429 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 430 | GCC_WARN_UNUSED_FUNCTION = YES; 431 | GCC_WARN_UNUSED_VARIABLE = YES; 432 | IPHONEOS_DEPLOYMENT_TARGET = 9.0; 433 | MTL_ENABLE_DEBUG_INFO = NO; 434 | SDKROOT = iphoneos; 435 | SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; 436 | SWIFT_VERSION = ""; 437 | TARGETED_DEVICE_FAMILY = "1,2"; 438 | VALIDATE_PRODUCT = YES; 439 | }; 440 | name = Release; 441 | }; 442 | 36B537D01D33409B0037CA02 /* Debug */ = { 443 | isa = XCBuildConfiguration; 444 | buildSettings = { 445 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 446 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 447 | CURRENT_PROJECT_VERSION = 1.6.0; 448 | INFOPLIST_FILE = ButtonStyleKitSample/Info.plist; 449 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 450 | MARKETING_VERSION = 1.6.0; 451 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.ButtonStyleKitSample; 452 | PRODUCT_NAME = "$(TARGET_NAME)"; 453 | SWIFT_VERSION = 5.0; 454 | TARGETED_DEVICE_FAMILY = "1,2"; 455 | }; 456 | name = Debug; 457 | }; 458 | 36B537D11D33409B0037CA02 /* Release */ = { 459 | isa = XCBuildConfiguration; 460 | buildSettings = { 461 | ALWAYS_EMBED_SWIFT_STANDARD_LIBRARIES = YES; 462 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 463 | CURRENT_PROJECT_VERSION = 1.6.0; 464 | INFOPLIST_FILE = ButtonStyleKitSample/Info.plist; 465 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 466 | MARKETING_VERSION = 1.6.0; 467 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.ButtonStyleKitSample; 468 | PRODUCT_NAME = "$(TARGET_NAME)"; 469 | SWIFT_VERSION = 5.0; 470 | TARGETED_DEVICE_FAMILY = "1,2"; 471 | }; 472 | name = Release; 473 | }; 474 | 36B537E11D3340CA0037CA02 /* Debug */ = { 475 | isa = XCBuildConfiguration; 476 | buildSettings = { 477 | CLANG_ENABLE_MODULES = YES; 478 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 479 | CURRENT_PROJECT_VERSION = 1.6.0; 480 | DEFINES_MODULE = YES; 481 | DYLIB_COMPATIBILITY_VERSION = 1; 482 | DYLIB_CURRENT_VERSION = 1; 483 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 484 | INFOPLIST_FILE = ButtonStyleKit/Info.plist; 485 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 486 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 487 | MARKETING_VERSION = 1.6.0; 488 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.ButtonStyleKit; 489 | PRODUCT_NAME = "$(TARGET_NAME)"; 490 | SKIP_INSTALL = YES; 491 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 492 | SWIFT_VERSION = 5.0; 493 | VERSIONING_SYSTEM = "apple-generic"; 494 | VERSION_INFO_PREFIX = ""; 495 | }; 496 | name = Debug; 497 | }; 498 | 36B537E21D3340CA0037CA02 /* Release */ = { 499 | isa = XCBuildConfiguration; 500 | buildSettings = { 501 | CLANG_ENABLE_MODULES = YES; 502 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = ""; 503 | CURRENT_PROJECT_VERSION = 1.6.0; 504 | DEFINES_MODULE = YES; 505 | DYLIB_COMPATIBILITY_VERSION = 1; 506 | DYLIB_CURRENT_VERSION = 1; 507 | DYLIB_INSTALL_NAME_BASE = "@rpath"; 508 | INFOPLIST_FILE = ButtonStyleKit/Info.plist; 509 | INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; 510 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 511 | MARKETING_VERSION = 1.6.0; 512 | PRODUCT_BUNDLE_IDENTIFIER = com.keygraphix.ios.ButtonStyleKit; 513 | PRODUCT_NAME = "$(TARGET_NAME)"; 514 | SKIP_INSTALL = YES; 515 | SWIFT_VERSION = 5.0; 516 | VERSIONING_SYSTEM = "apple-generic"; 517 | VERSION_INFO_PREFIX = ""; 518 | }; 519 | name = Release; 520 | }; 521 | /* End XCBuildConfiguration section */ 522 | 523 | /* Begin XCConfigurationList section */ 524 | 36B537B81D33409B0037CA02 /* Build configuration list for PBXProject "ButtonStyleKitSample" */ = { 525 | isa = XCConfigurationList; 526 | buildConfigurations = ( 527 | 36B537CD1D33409B0037CA02 /* Debug */, 528 | 36B537CE1D33409B0037CA02 /* Release */, 529 | ); 530 | defaultConfigurationIsVisible = 0; 531 | defaultConfigurationName = Release; 532 | }; 533 | 36B537CF1D33409B0037CA02 /* Build configuration list for PBXNativeTarget "ButtonStyleKitSample" */ = { 534 | isa = XCConfigurationList; 535 | buildConfigurations = ( 536 | 36B537D01D33409B0037CA02 /* Debug */, 537 | 36B537D11D33409B0037CA02 /* Release */, 538 | ); 539 | defaultConfigurationIsVisible = 0; 540 | defaultConfigurationName = Release; 541 | }; 542 | 36B537E01D3340CA0037CA02 /* Build configuration list for PBXNativeTarget "ButtonStyleKit" */ = { 543 | isa = XCConfigurationList; 544 | buildConfigurations = ( 545 | 36B537E11D3340CA0037CA02 /* Debug */, 546 | 36B537E21D3340CA0037CA02 /* Release */, 547 | ); 548 | defaultConfigurationIsVisible = 0; 549 | defaultConfigurationName = Release; 550 | }; 551 | /* End XCConfigurationList section */ 552 | }; 553 | rootObject = 36B537B51D33409B0037CA02 /* Project object */; 554 | } 555 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample.xcodeproj/xcshareddata/xcschemes/ButtonStyleKit.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 43 | 44 | 50 | 51 | 52 | 53 | 59 | 60 | 66 | 67 | 68 | 69 | 71 | 72 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample.xcodeproj/xcshareddata/xcschemes/ButtonStyleKitSample.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 37 | 38 | 39 | 40 | 41 | 42 | 52 | 54 | 60 | 61 | 62 | 63 | 69 | 71 | 77 | 78 | 79 | 80 | 82 | 83 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | private func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(_ application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(_ application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(_ application: UIApplication) { 33 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(_ application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(_ application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 36 | 48 | 60 | 69 | 80 | 90 | 100 | 110 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/ButtonGroupHelper.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ButtonGroup.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/27. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | struct RadioGroup { 13 | 14 | var selectedValues: [Bool] { 15 | return group.map { $0.value } 16 | } 17 | 18 | private var group: [SampleButtonRadioStyle] 19 | 20 | init(buttons: inout [SampleButtonRadioStyle]) { 21 | group = buttons 22 | } 23 | 24 | // Enabled / Desabled 25 | func enabled() { 26 | group.forEach { 27 | $0.currentState = .normal 28 | } 29 | } 30 | 31 | func disabled() { 32 | unSelectAll() 33 | group.forEach { 34 | $0.currentState = .disabled 35 | } 36 | } 37 | 38 | // Select Action 39 | func select(index: Int) { 40 | 41 | 42 | if group.endIndex <= index { 43 | return 44 | } 45 | 46 | if group[index].value == true { 47 | group[index].value = false 48 | return 49 | } 50 | 51 | unSelectAll() 52 | group[index].value = true 53 | } 54 | 55 | func selectAll() { 56 | group.forEach { 57 | $0.value = true 58 | } 59 | } 60 | 61 | func unSelectAll() { 62 | group.forEach { 63 | $0.value = false 64 | } 65 | } 66 | 67 | // Print 68 | func printValues() { 69 | print(selectedValues) 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/SampleButtonCheckboxStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleButtonCheckboxStyle.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | final class SampleButtonCheckboxStyle: ButtonStyleSelectableBase { 13 | 14 | private let buttonStyle = ButtonStyleBuilder() 15 | private var checkImageView = UIImageView() 16 | 17 | final override func initializedTrigger() { 18 | /*---------- Common Settings ----------*/ 19 | buttonStyle 20 | .setButton(self) 21 | .setState(.all) 22 | .setFont(UIFont.systemFont(ofSize: 16)) 23 | .setContentHorizontalAlignment(.left) 24 | .setContentVerticalAlignment(.center) 25 | .setTitleEdgeInsets(top: 0, right: 0, bottom: 0, left: 30) 26 | .setExclusiveTouch(true) 27 | .build() 28 | 29 | /*---------- For State Settings ----------*/ 30 | buttonStyle 31 | .setState(.normal) 32 | .setTitle("checkbox") 33 | .build() 34 | 35 | checkImageView = buttonStyle.createImageView(frame: CGRect(x: 0, y: 4, width: 28, height: 28), 36 | normal: UIImage(named: "checkbox")!, highlighted: UIImage(named: "checkbox_on")!) 37 | addSubview(checkImageView) 38 | 39 | buttonStyle.apply() 40 | } 41 | 42 | final override var currentState: ButtonStyleKit.ButtonState { 43 | didSet { 44 | /*---------- ButtonState Settings ----------*/ 45 | switch currentState { 46 | case .selected: 47 | checkImageView.isHighlighted = true 48 | default: 49 | checkImageView.isHighlighted = false 50 | } 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/SampleButtonRadioStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleButtonRadioStyle.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | final class SampleButtonRadioStyle: ButtonStyleSelectableBase { 13 | 14 | private let buttonStyle = ButtonStyleBuilder() 15 | private var checkImageView = UIImageView() 16 | 17 | final override func initializedTrigger() { 18 | 19 | let black = UIColor.black 20 | let lightGray = UIColor.lightGray 21 | 22 | /*---------- Common Settings ----------*/ 23 | buttonStyle 24 | .setButton(self) 25 | .setState(.all) 26 | .setFont(UIFont.systemFont(ofSize: 16)) 27 | .setContentHorizontalAlignment(.left) 28 | .setContentVerticalAlignment(.center) 29 | .setTitleEdgeInsets(top: 0, right: 0, bottom: 0, left: 30) 30 | .setExclusiveTouch(true) 31 | .build() 32 | 33 | /*---------- For State Settings ----------*/ 34 | buttonStyle 35 | .setState(.normal) 36 | .setTitleColor(black) 37 | .build() 38 | 39 | buttonStyle 40 | .setState(.selected) 41 | .setTitleColor(black) 42 | .build() 43 | 44 | buttonStyle 45 | .setState(.disabled) 46 | .setTitleColor(lightGray) 47 | .build() 48 | 49 | checkImageView = UIImageView(frame: CGRect(x: 0, y: 4, width: 28, height: 28)) 50 | checkImageView.image = UIImage(named: "radio") 51 | addSubview(checkImageView) 52 | 53 | buttonStyle.apply() 54 | } 55 | 56 | final override var currentState: ButtonStyleKit.ButtonState { 57 | didSet { 58 | /*---------- ButtonState Settings ----------*/ 59 | switch currentState { 60 | case .disabled: 61 | checkImageView.image = UIImage(named: "radio_off") 62 | case .selected: 63 | checkImageView.image = UIImage(named: "radio_on") 64 | default: 65 | checkImageView.image = UIImage(named: "radio") 66 | } 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/SampleButtonShadowStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleButtonShadowStyle.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2018/09/21. 6 | // Copyright © 2018年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | class SampleButtonShadowStyle: ButtonStyleStandardBase { 13 | private let buttonStyle = ButtonStyleBuilder() 14 | 15 | final override func initializedTrigger() { 16 | let blue = UIColor(red: 0.0/255.0, green: 122.0/255.0, blue: 255.0/255.0, alpha: 1.0) 17 | let blueHighlighted = UIColor(red: 0.0/255.0, green: 100.0/255.0, blue: 210.0/255.0, alpha: 1.0) 18 | let gray = UIColor.lightGray 19 | let white = UIColor.white 20 | let black = UIColor.black 21 | 22 | /*---------- Common Settings ----------*/ 23 | buttonStyle 24 | .setButton(self) 25 | .setState(.all) 26 | .setTitle("Shadow") 27 | .setTitleColor(white) 28 | .setFont(UIFont.boldSystemFont(ofSize: 16)) 29 | .setCornerRadius(8.0) 30 | .setShadowColor(black) 31 | .setShadowOffset(CGSize(width: 1.0, height: 1.0)) 32 | .setShadowOpacity(0.3) 33 | .setShadowRadius(2.0) 34 | .setExclusiveTouch(true) 35 | .build() 36 | 37 | /*---------- For State Settings ----------*/ 38 | buttonStyle 39 | .setState(.normal) 40 | .setBackgroundColor(blue) 41 | .build() 42 | 43 | buttonStyle 44 | .setState(.highlighted) 45 | .setBackgroundColor(blueHighlighted) 46 | .build() 47 | 48 | buttonStyle 49 | .setState(.disabled) 50 | .setBackgroundColor(gray) 51 | .build() 52 | 53 | buttonStyle.apply() 54 | } 55 | 56 | final override var currentState: ButtonStyleKit.ButtonState { 57 | didSet { 58 | buttonStyle.apply() 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/SampleButtonStandardStyle.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SampleButtonStandardStyle.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | final class SampleButtonStandardStyle: ButtonStyleStandardBase { 13 | 14 | private let buttonStyle = ButtonStyleBuilder() 15 | 16 | final override func initializedTrigger() { 17 | let blue = UIColor(red: 0.0/255.0, green: 122.0/255.0, blue: 255.0/255.0, alpha: 1.0) 18 | let white = UIColor.white 19 | let orange = UIColor.orange 20 | let lightGray = UIColor.lightGray 21 | let whiteImage = buttonStyle.createViewToImage(color: white) 22 | 23 | /*---------- Common Settings ----------*/ 24 | buttonStyle 25 | .setButton(self) 26 | .setState(.all) 27 | .setFont(UIFont.systemFont(ofSize: 16)) 28 | .setCornerRadius(8.0) 29 | .setBorderWidth(1.0) 30 | .setClipsToBounds(true) 31 | .setExclusiveTouch(true) 32 | .build() 33 | 34 | /*---------- For State Settings ----------*/ 35 | buttonStyle 36 | .setState(.normal) 37 | .setTitle("normal") 38 | .setTitleColor(blue) 39 | .setBackgroundImage(whiteImage!) 40 | .setBorderColor(blue) 41 | .build() 42 | 43 | buttonStyle 44 | .setState(.highlighted) 45 | .setTitle("highlighted") 46 | .setTitleColor(orange) 47 | .setBackgroundImage(whiteImage!) 48 | .setBorderColor(orange) 49 | .build() 50 | 51 | buttonStyle 52 | .setState(.disabled) 53 | .setTitle("disabled") 54 | .setTitleColor(lightGray) 55 | .setBackgroundImage(whiteImage!) 56 | .setBorderColor(lightGray) 57 | .build() 58 | 59 | buttonStyle.apply() 60 | } 61 | 62 | final override var currentState: ButtonStyleKit.ButtonState { 63 | didSet { 64 | buttonStyle.apply() 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "checkbox@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "checkbox@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox.imageset/checkbox@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox.imageset/checkbox@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox.imageset/checkbox@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox.imageset/checkbox@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_off.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "checkbox_off@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "checkbox_off@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_off.imageset/checkbox_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_off.imageset/checkbox_off@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_off.imageset/checkbox_off@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_off.imageset/checkbox_off@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_on.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "checkbox_on@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "checkbox_on@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_on.imageset/checkbox_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_on.imageset/checkbox_on@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_on.imageset/checkbox_on@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/checkbox_on.imageset/checkbox_on@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "radio@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "radio@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio.imageset/radio@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio.imageset/radio@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio.imageset/radio@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio.imageset/radio@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_off.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "radio_off@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "radio_off@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_off.imageset/radio_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_off.imageset/radio_off@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_off.imageset/radio_off@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_off.imageset/radio_off@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_on.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "scale" : "1x" 6 | }, 7 | { 8 | "idiom" : "universal", 9 | "filename" : "radio_on@2x.png", 10 | "scale" : "2x" 11 | }, 12 | { 13 | "idiom" : "universal", 14 | "filename" : "radio_on@3x.png", 15 | "scale" : "3x" 16 | } 17 | ], 18 | "info" : { 19 | "version" : 1, 20 | "author" : "xcode" 21 | } 22 | } -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_on.imageset/radio_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_on.imageset/radio_on@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_on.imageset/radio_on@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/ButtonStyleKitSample/ButtonStyle/images.xcassets/radio_on.imageset/radio_on@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | $(MARKETING_VERSION) 19 | CFBundleVersion 20 | $(CURRENT_PROJECT_VERSION) 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | UIInterfaceOrientationLandscapeLeft 35 | UIInterfaceOrientationLandscapeRight 36 | 37 | UISupportedInterfaceOrientations~ipad 38 | 39 | UIInterfaceOrientationPortrait 40 | UIInterfaceOrientationPortraitUpsideDown 41 | UIInterfaceOrientationLandscapeLeft 42 | UIInterfaceOrientationLandscapeRight 43 | 44 | 45 | 46 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/ButtonStyleKitSample/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // ButtonStyleKitSample 4 | // 5 | // Created by keygx on 2016/08/04. 6 | // Copyright © 2016年 keygx. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import ButtonStyleKit 11 | 12 | class ViewController: UIViewController { 13 | 14 | @IBOutlet weak var button: SampleButtonStandardStyle! 15 | @IBOutlet weak var checkbox: SampleButtonCheckboxStyle! 16 | @IBOutlet weak var radioA: SampleButtonRadioStyle! 17 | @IBOutlet weak var radioB: SampleButtonRadioStyle! 18 | @IBOutlet weak var radioC: SampleButtonRadioStyle! 19 | 20 | var group: RadioGroup? 21 | 22 | override func viewDidLoad() { 23 | super.viewDidLoad() 24 | 25 | var array = [radioA!, radioB!, radioC!] 26 | group = RadioGroup(buttons: &array) 27 | 28 | // Standard Button 29 | button.tag = 1 30 | button.setClickHandler { sender in 31 | print("clicked tag: \(sender.tag)") 32 | } 33 | 34 | radioOnOff() 35 | 36 | // Checkbox 37 | checkbox.setClickHandler { [unowned self] sender in 38 | self.checkbox.value = !self.checkbox.value 39 | print("checkbox: \(self.checkbox.value)") 40 | 41 | self.radioOnOff() 42 | } 43 | 44 | // Radio 45 | radioA.setClickHandler { [unowned self] sender in 46 | self.group?.select(index: 0) 47 | self.group?.printValues() 48 | } 49 | radioB.setClickHandler { [unowned self] sender in 50 | self.group?.select(index: 1) 51 | self.group?.printValues() 52 | } 53 | radioC.setClickHandler { [unowned self] sender in 54 | self.group?.select(index: 2) 55 | self.group?.printValues() 56 | } 57 | } 58 | 59 | func radioOnOff() { 60 | if self.checkbox.value { 61 | group?.enabled() 62 | } else { 63 | group?.disabled() 64 | } 65 | 66 | group?.printValues() 67 | } 68 | 69 | // Button Style Change 70 | @IBAction func btn1NormalAction(sender: UIButton) { 71 | button.currentState = .normal 72 | } 73 | @IBAction func btn1HighlightedAction(sender: UIButton) { 74 | button.currentState = .highlighted 75 | } 76 | @IBAction func btn1DisabledAction(sender: UIButton) { 77 | button.currentState = .disabled 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/button.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/button.afdesign -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox_off@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox_off@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox_off@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox_on@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/checkbox_on@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/checkbox_on@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio_off@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio_off@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio_off@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio_off@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio_on@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio_on@2x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/radio_on@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/radio_on@3x.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/StandardStyle.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/StandardStyle.afdesign -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/StandardStyle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/StandardStyle.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/button_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/button_disabled.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/button_highlighted.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/button_highlighted.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/button_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/button_normal.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/screen.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/screen.afdesign -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/screen.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/screen.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/screen01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/screen01.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/screen02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/screen02.png -------------------------------------------------------------------------------- /ButtonStyleKitSample/images/readme/xcode.afdesign: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/keygx/ButtonStyleKit/af5c4288fc44ef8cfb92dfa933c1474edf6affd1/ButtonStyleKitSample/images/readme/xcode.afdesign -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Yukihiko Kagiyama 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in 13 | all copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | THE SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ButtonStyleKit 2 | 3 | ButtonStyleKit is helper library for UIButton custom styles. 4 | 5 | ## Requirements 6 | - Swift 5 7 | - iOS 9.0 or later 8 | 9 | ## Installation 10 | 11 | ### Carthage 12 | 13 | ```Cartfile 14 | github "keygx/ButtonStyleKit" 15 | ``` 16 | 17 | ### CocoaPods 18 | 19 | ```PodFile 20 | pod 'ButtonStyleKit', :git => 'https://github.com/keygx/ButtonStyleKit' 21 | ``` 22 | 23 | 24 | ### Swift versions support 25 | 26 | - Swift 5, tag "swift5" 27 | - Swift 4.2, tag "swift4.2" 28 | - Swift 4.1, tag "swift4.1" 29 | - Swift 4.0, tag "swift4.0" 30 | 31 | 32 | ## Usage 33 | 34 | ### Standard Style Example 35 | 36 | ![](ButtonStyleKitSample/images/readme/StandardStyle.png) 37 | 38 | #### make custom style 39 | 40 | ```SampleButtonStandardStyle.swift 41 | import UIKit 42 | import ButtonStyleKit 43 | 44 | final class SampleButtonStandardStyle: ButtonStyleStandardBase { 45 | 46 | private let buttonStyle = ButtonStyleBuilder() 47 | 48 | final override func initializedTrigger() { 49 | let blue = UIColor(red: 0.0/255.0, green: 122.0/255.0, blue: 255.0/255.0, alpha: 1.0) 50 | let white = UIColor.white 51 | let orange = UIColor.orange 52 | let lightGray = UIColor.lightGray 53 | let whiteImage = buttonStyle.createViewToImage(color: white) 54 | 55 | /*---------- Common Settings ----------*/ 56 | buttonStyle 57 | .setButton(self) 58 | .setState(.all) 59 | .setFont(UIFont.systemFont(ofSize: 16)) 60 | .setCornerRadius(8.0) 61 | .setBorderWidth(1.0) 62 | .setClipsToBounds(true) 63 | .setExclusiveTouch(true) 64 | .build() 65 | 66 | /*---------- For State Settings ----------*/ 67 | buttonStyle 68 | .setState(.normal) 69 | .setTitle("normal") 70 | .setTitleColor(blue) 71 | .setBackgroundImage(whiteImage!) 72 | .setBorderColor(blue) 73 | .build() 74 | 75 | buttonStyle 76 | .setState(.highlighted) 77 | .setTitle("highlighted") 78 | .setTitleColor(orange) 79 | .setBackgroundImage(whiteImage!) 80 | .setBorderColor(orange) 81 | .build() 82 | 83 | buttonStyle 84 | .setState(.disabled) 85 | .setTitle("disabled") 86 | .setTitleColor(lightGray) 87 | .setBackgroundImage(whiteImage!) 88 | .setBorderColor(lightGray) 89 | .build() 90 | 91 | buttonStyle.apply() 92 | } 93 | 94 | final override var currentState: ButtonStyleKit.ButtonState { 95 | didSet { 96 | buttonStyle.apply() 97 | } 98 | } 99 | } 100 | ``` 101 | 102 | #### storyboard settings 103 | 104 | - set Button Type "Custom" 105 | - set Custom Class "SampleButtonStandardStyle" 106 | 107 | ![](ButtonStyleKitSample/images/readme/screen.png) 108 | 109 | 110 | #### use viewcontroller 111 | 112 | ```ViewController.swift 113 | import ButtonStyleKit 114 | 115 | class ViewController: UIViewController { 116 | 117 | @IBOutlet weak var button: SampleButtonStandardStyle! 118 | 119 | ~~~ 120 | 121 | button.setClickHandler { sender in 122 | print("clicked tag: \(sender.tag)") 123 | } 124 | 125 | ``` 126 | 127 | **For more information, please refer to the sample project** 128 | 129 | 130 | ## License 131 | 132 | ButtonStyleKit is released under the MIT license. See LICENSE for details. 133 | 134 | ## Author 135 | 136 | Yukihiko Kagiyama (keygx) 137 | --------------------------------------------------------------------------------