├── .gitignore ├── KSTabView.podspec ├── KSTabView.swift ├── KSTabView.xcodeproj ├── project.pbxproj └── project.xcworkspace │ └── contents.xcworkspacedata ├── KSTabView ├── AppDelegate.swift ├── Base.lproj │ └── Main.storyboard ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.swift └── images │ ├── altFacebook.png │ ├── facebook.png │ ├── google.png │ ├── instagram.png │ └── twitter.png ├── KSTabViewTests ├── Info.plist └── KSTabViewTests.swift ├── LICENSE ├── README.md └── demo.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | .DS_Store 4 | build/ 5 | *.pbxuser 6 | !default.pbxuser 7 | *.mode1v3 8 | !default.mode1v3 9 | *.mode2v3 10 | !default.mode2v3 11 | *.perspectivev3 12 | !default.perspectivev3 13 | xcuserdata 14 | *.xccheckout 15 | *.moved-aside 16 | DerivedData 17 | *.hmap 18 | *.ipa 19 | *.xcuserstate 20 | -------------------------------------------------------------------------------- /KSTabView.podspec: -------------------------------------------------------------------------------- 1 | Pod::Spec.new do |s| 2 | s.name = 'KSTabView' 3 | s.version = '0.3.2' 4 | s.license = 'MIT' 5 | s.summary = 'Simple and Lightweight TabView for Mac' 6 | s.homepage = 'https://github.com/kaunteya/KSTabView' 7 | s.authors = { 'Kaunteya Suryawanshi' => 'k.suryawanshi@gmail.com' } 8 | s.source = { :git => 'https://github.com/kaunteya/KSTabView.git', :tag => s.version } 9 | 10 | s.platform = :osx, '10.9' 11 | s.requires_arc = true 12 | 13 | s.source_files = 'KSTabView.swift' 14 | end 15 | -------------------------------------------------------------------------------- /KSTabView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KSTabController.swift 3 | // KSTabView 4 | // 5 | // Created by Kaunteya Suryawanshi on 13/06/15. 6 | // Copyright (c) 2015 com.kaunteya. All rights reserved. 7 | // 8 | 9 | import Foundation 10 | import Cocoa 11 | 12 | @IBDesignable 13 | public class KSTabView: NSControl { 14 | 15 | enum SelectionType: Int { 16 | case None = 0, One, Any 17 | } 18 | 19 | @IBInspectable var backgroundColor: NSColor! = NSColor(calibratedRed: 5 / 255, green: 105 / 255, blue: 92 / 255, alpha: 1) 20 | @IBInspectable var hoverColor: NSColor! = NSColor(calibratedRed: 12 / 255, green: 81 / 255, blue: 68 / 255, alpha: 1) 21 | 22 | @IBInspectable var labelColor: NSColor! = NSColor(calibratedRed: 137/255, green: 185/255, blue: 175/255, alpha: 1.0) 23 | @IBInspectable var selectionColor: NSColor! = NSColor.whiteColor() 24 | @IBInspectable var underlineColor: NSColor! = NSColor.whiteColor() 25 | 26 | @IBInspectable var fontSize: CGFloat = 16 27 | public var labelFont: NSFont = NSFont.labelFontOfSize(16) // wish this was @IBInspectable 28 | @IBInspectable var buttonPadding: CGFloat = 10 29 | 30 | private var leftButtonList = [KSButton]() 31 | private var rightButtonList = [KSButton]() 32 | 33 | public var leftImagePosition = NSCellImagePosition.ImageLeft 34 | public var rightImagePosition = NSCellImagePosition.ImageLeft 35 | 36 | var selectionType: SelectionType = .One { 37 | didSet { 38 | self.selectedButtons = [] 39 | } 40 | } 41 | 42 | public var selectedButtons: [String] { 43 | get { 44 | return (leftButtonList + rightButtonList).filter { $0.selected }.map { $0.identifier }.filter{ $0 != nil}.map {$0!} 45 | } 46 | 47 | set(newIdentifierList) { 48 | 49 | switch selectionType { 50 | case .One: 51 | if newIdentifierList.count > 1 { 52 | Swift.print("Only one button can be selected") 53 | return 54 | } 55 | default:() 56 | } 57 | 58 | for button in (leftButtonList + rightButtonList) { 59 | if let validIdentifier = button.identifier where newIdentifierList.contains(validIdentifier) { 60 | button.selected = true 61 | } else { 62 | button.selected = false 63 | } 64 | } 65 | } 66 | } 67 | 68 | required public init?(coder: NSCoder) { 69 | super.init(coder: coder) 70 | } 71 | 72 | override public func awakeFromNib() 73 | { 74 | // if fontSize was changed via the inspector, make sure it's changed here too... 75 | if fontSize != 16.0 76 | { 77 | if let newFont = NSFont(name: self.labelFont.fontName, size: fontSize) 78 | { 79 | self.labelFont = newFont 80 | } 81 | } 82 | } 83 | override public func drawRect(dirtyRect: NSRect) { 84 | backgroundColor.setFill() 85 | NSRectFillUsingOperation(dirtyRect, NSCompositingOperation.CompositeSourceOver) 86 | } 87 | 88 | public func removeLeftButtons() -> KSTabView { 89 | for aButton in leftButtonList { 90 | aButton.removeFromSuperview() 91 | } 92 | leftButtonList.removeAll(keepCapacity: false) 93 | return self 94 | } 95 | 96 | public func removeRightButtons() -> KSTabView { 97 | for aButton in rightButtonList { 98 | aButton.removeFromSuperview() 99 | } 100 | rightButtonList.removeAll(keepCapacity: false) 101 | return self 102 | } 103 | 104 | public func pushButtonLeft(identifier: String, title: String) -> KSTabView { 105 | _pushButton(identifier, title: title, image: nil, alternateImage: nil, align: .Left) 106 | return self 107 | } 108 | 109 | public func pushButtonLeft(identifier: String, image: NSImage, alternateImage: NSImage?) -> KSTabView { 110 | _pushButton(identifier, title: nil, image: image, alternateImage: alternateImage, align: .Left) 111 | return self 112 | } 113 | public func pushButtonLeft(identifier: String, title: String, image: NSImage, alternateImage: NSImage?) -> KSTabView { 114 | _pushButton(identifier, title: title, image: image, alternateImage: alternateImage, align: .Left) 115 | return self 116 | } 117 | 118 | public func pushButtonRight(identifier: String, title: String) -> KSTabView { 119 | _pushButton(identifier, title: title, image: nil, alternateImage: nil, align: .Right) 120 | return self 121 | } 122 | 123 | public func pushButtonRight(identifier: String, image: NSImage, alternateImage: NSImage?) -> KSTabView { 124 | _pushButton(identifier, title: nil, image: image, alternateImage: alternateImage, align: .Right) 125 | return self 126 | } 127 | 128 | public func pushButtonRight(identifier: String, title: String, image: NSImage, alternateImage: NSImage?) -> KSTabView { 129 | _pushButton(identifier, title: title, image: image, alternateImage: alternateImage, align: .Right) 130 | return self 131 | } 132 | 133 | private func _pushButton(identifier: String, title: String?, image: NSImage?, alternateImage: NSImage?, align: NSLayoutAttribute) { 134 | 135 | var imagePosition: NSCellImagePosition = NSCellImagePosition.NoImage 136 | if image != nil { 137 | if align == .Left { 138 | imagePosition = leftImagePosition 139 | } else if align == .Right { 140 | imagePosition = rightImagePosition 141 | } 142 | } 143 | 144 | let coreButton = NSButton(frame: NSZeroRect) 145 | coreButton.title = title ?? "" 146 | coreButton.identifier = identifier 147 | coreButton.image = image 148 | coreButton.alternateImage = alternateImage 149 | coreButton.imagePosition = imagePosition 150 | coreButton.updateButtonFortabView(self) 151 | 152 | let button = KSButton(aButton: coreButton, tabView: self) 153 | self.addSubview(button) 154 | button.translatesAutoresizingMaskIntoConstraints = false 155 | 156 | var formatString: String! 157 | var viewsDictionary: [String: AnyObject]! 158 | if align == NSLayoutAttribute.Left { 159 | if let leftButton = leftButtonList.last { 160 | viewsDictionary = ["button" : button, "leftButton" : leftButton] 161 | formatString = "H:[leftButton][button(size)]" 162 | } else { 163 | viewsDictionary = ["button": button] 164 | formatString = "H:|[button(size)]" 165 | } 166 | leftButtonList.append(button) 167 | } else if align == NSLayoutAttribute.Right { 168 | if let rightButton = rightButtonList.last { 169 | viewsDictionary = ["button" : button, "rightButton" : rightButton] 170 | formatString = "H:[button(size)][rightButton]" 171 | } else { 172 | viewsDictionary = ["button": button] 173 | formatString = "H:[button(size)]|" 174 | } 175 | rightButtonList.append(button) 176 | } 177 | 178 | self.addConstraints( 179 | NSLayoutConstraint.constraintsWithVisualFormat( 180 | formatString, 181 | options: NSLayoutFormatOptions(rawValue: 0), 182 | metrics: ["size": button.frame.size.width], 183 | views: viewsDictionary) 184 | ) 185 | self.addConstraints( 186 | NSLayoutConstraint.constraintsWithVisualFormat( 187 | "V:[button(height)]", 188 | options: NSLayoutFormatOptions(rawValue: 0), 189 | metrics: ["height": button.frame.size.height], 190 | views: ["button" : button]) 191 | ) 192 | } 193 | func buttonPressed(sender: KSButton) { 194 | switch selectionType { 195 | case .One: 196 | self.selectedButtons = [sender.identifier!] 197 | case .Any: 198 | if sender.selected { 199 | self.selectedButtons = self.selectedButtons.filter{ $0 != sender.identifier } 200 | } else { 201 | self.selectedButtons.append(sender.identifier!) 202 | } 203 | default:() 204 | } 205 | 206 | NSApplication.sharedApplication().sendAction(self.action, to: self.target, from: sender.identifier as NSString?) 207 | } 208 | } 209 | 210 | //MARK: KSButton 211 | extension KSTabView { 212 | class KSButton: NSControl { 213 | 214 | private let parentTabView: KSTabView 215 | private var mouseInside = false { 216 | didSet { 217 | self.needsDisplay = true 218 | } 219 | } 220 | var underLayer = CAShapeLayer() 221 | private let selectionLineHeight: CGFloat 222 | 223 | private var button: NSButton! 224 | 225 | var selected = false { 226 | didSet { 227 | let activeColor = self.selected ? parentTabView.selectionColor : parentTabView.labelColor 228 | button.setAttributedString(parentTabView.labelFont, color: activeColor) 229 | button.state = self.selected ? NSOnState : NSOffState 230 | 231 | CATransaction.begin() 232 | if self.selected { 233 | CATransaction.setAnimationDuration(0.5) 234 | } else { 235 | CATransaction.setDisableActions(true) 236 | } 237 | let timing = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseOut) 238 | CATransaction.setAnimationTimingFunction(timing) 239 | underLayer.strokeStart = 0 240 | underLayer.strokeEnd = self.selected ? 1 : 0 241 | CATransaction.commit() 242 | } 243 | } 244 | 245 | var trackingArea: NSTrackingArea! 246 | override func updateTrackingAreas() { 247 | super.updateTrackingAreas() 248 | if trackingArea != nil { 249 | self.removeTrackingArea(trackingArea) 250 | } 251 | trackingArea = NSTrackingArea(rect: self.bounds, options: [NSTrackingAreaOptions.MouseEnteredAndExited, NSTrackingAreaOptions.ActiveAlways], owner: self, userInfo: nil) 252 | self.addTrackingArea(trackingArea) 253 | } 254 | 255 | init(aButton: NSButton, tabView: KSTabView) { 256 | parentTabView = tabView 257 | selectionLineHeight = parentTabView.labelFont.pointSize / 5 258 | 259 | super.init(frame: NSZeroRect) 260 | self.wantsLayer = true 261 | self.identifier = aButton.identifier 262 | self.button = aButton 263 | self.target = tabView 264 | self.action = #selector(buttonPressed) 265 | self.addSubview(self.button) 266 | self.button.frame.origin = NSMakePoint(parentTabView.buttonPadding, selectionLineHeight * 1.5) 267 | 268 | let frameWidth = self.button.frame.width + (parentTabView.buttonPadding * 2) 269 | 270 | makeUnderLayer(frameWidth) 271 | 272 | /// Frame Size 273 | let frameHeight = tabView.labelFont.pointSize * 3.0 274 | self.frame.size = NSSize(width: frameWidth, height: frameHeight) 275 | } 276 | 277 | func makeUnderLayer(frameWidth: CGFloat) { 278 | // let layerWidth = frameWidth - (selectionLineHeight * 2) 279 | let path = NSBezierPath() 280 | path.moveToPoint(NSMakePoint(selectionLineHeight, 2)) 281 | path.lineToPoint(NSMakePoint(frameWidth - selectionLineHeight, 2)) 282 | underLayer.path = path.CGPath 283 | underLayer.strokeEnd = 0 284 | underLayer.lineWidth = selectionLineHeight 285 | underLayer.strokeColor = parentTabView.underlineColor.CGColor 286 | self.layer!.addSublayer(underLayer) 287 | } 288 | 289 | required init?(coder: NSCoder) { fatalError("Init from IB not supported") } 290 | 291 | override func mouseEntered(theEvent: NSEvent) { mouseInside = true } 292 | 293 | override func mouseExited(theEvent: NSEvent) { mouseInside = false } 294 | 295 | override func mouseUp(theEvent: NSEvent) { 296 | NSApplication.sharedApplication().sendAction(self.action, to: self.target, from: self) 297 | } 298 | 299 | override func drawRect(dirtyRect: NSRect) { 300 | if mouseInside { 301 | parentTabView.hoverColor.setFill() 302 | } else { 303 | parentTabView.backgroundColor.setFill() 304 | } 305 | NSRectFillUsingOperation(dirtyRect, NSCompositingOperation.CompositeSourceOver) 306 | } 307 | } 308 | } 309 | 310 | extension NSButton { 311 | private class ButtonCell: NSButtonCell { 312 | init(title: String, cellImage: NSImage?) { 313 | super.init(imageCell: cellImage) 314 | self.title = title 315 | self.imageDimsWhenDisabled = false 316 | } 317 | 318 | required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } 319 | 320 | override func drawTitle(title: NSAttributedString, withFrame frame: NSRect, inView controlView: NSView) -> NSRect { 321 | return super.drawTitle(self.attributedTitle, withFrame: frame, inView: controlView) 322 | } 323 | } 324 | 325 | func setAttributedString(font: NSFont, color: NSColor) { 326 | let colorTitle = NSMutableAttributedString(attributedString: self.attributedTitle) 327 | 328 | let titleRange = NSMakeRange(0, colorTitle.length) 329 | colorTitle.addAttribute(NSForegroundColorAttributeName, value: color, range: titleRange) 330 | colorTitle.addAttribute(NSFontAttributeName, value: font, range: titleRange) 331 | self.attributedTitle = colorTitle 332 | } 333 | 334 | func updateButtonFortabView(tabView: KSTabView){ 335 | let oldImagePosition = self.imagePosition 336 | self.setButtonType(NSButtonType.ToggleButton) 337 | 338 | self.cell = ButtonCell(title: self.title, cellImage: self.image) 339 | self.imagePosition = oldImagePosition 340 | self.bordered = false 341 | self.enabled = false 342 | self.image?.size = NSMakeSize(tabView.labelFont.pointSize * 1.7, tabView.labelFont.pointSize * 1.7) 343 | self.alternateImage?.size = NSMakeSize(tabView.labelFont.pointSize * 1.7, tabView.labelFont.pointSize * 1.7) 344 | 345 | self.setAttributedString(tabView.labelFont, color: tabView.labelColor) 346 | self.sizeToFit() 347 | } 348 | } 349 | 350 | extension NSBezierPath { 351 | /// Converts NSBezierPath to CGPath 352 | var CGPath: CGPathRef { 353 | let path = CGPathCreateMutable() 354 | let points = UnsafeMutablePointer.alloc(3) 355 | let numElements = self.elementCount 356 | 357 | for index in 0.. 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /KSTabView/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // KSTabView 4 | // 5 | // Created by Kaunteya Suryawanshi on 13/06/15. 6 | // Copyright (c) 2015 com.kaunteya. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | @NSApplicationMain 12 | class AppDelegate: NSObject, NSApplicationDelegate { 13 | 14 | 15 | 16 | func applicationDidFinishLaunching(aNotification: NSNotification) { 17 | // Insert code here to initialize your application 18 | } 19 | 20 | func applicationWillTerminate(aNotification: NSNotification) { 21 | // Insert code here to tear down your application 22 | } 23 | 24 | 25 | } 26 | 27 | -------------------------------------------------------------------------------- /KSTabView/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 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 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 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | 257 | 258 | 259 | 260 | 261 | 262 | 263 | 264 | 265 | 266 | 267 | 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | 281 | 282 | 283 | 284 | 285 | 286 | 287 | 288 | 289 | 290 | 291 | 292 | 293 | 294 | 295 | 296 | 297 | 298 | 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | 309 | 310 | 311 | 312 | 313 | 314 | 315 | 316 | 317 | 318 | 319 | 320 | 321 | 322 | 323 | 324 | 325 | 326 | 327 | 328 | 329 | 330 | 331 | 332 | 333 | 334 | 335 | 336 | 337 | 338 | 339 | 340 | 341 | 342 | 343 | 344 | 345 | 346 | 347 | 348 | 349 | 350 | 351 | 352 | 353 | 354 | 355 | 356 | 357 | 358 | 359 | 360 | 361 | 362 | 363 | 364 | 365 | 366 | 367 | 368 | 369 | 370 | 371 | 372 | 373 | 374 | 375 | 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 | 452 | 453 | 454 | 455 | 456 | 457 | 458 | 459 | 460 | 461 | 462 | 463 | 464 | 465 | 466 | 467 | 468 | 469 | 470 | 471 | 472 | 473 | 474 | 475 | 476 | 477 | 478 | 479 | 480 | 481 | 482 | 483 | 484 | 485 | 486 | 487 | 488 | 489 | 490 | 491 | 492 | 493 | 494 | 495 | 496 | 497 | 498 | 499 | 500 | 501 | 502 | 503 | 504 | 505 | 506 | 507 | 508 | 509 | Default 510 | 511 | 512 | 513 | 514 | 515 | 516 | Left to Right 517 | 518 | 519 | 520 | 521 | 522 | 523 | Right to Left 524 | 525 | 526 | 527 | 528 | 529 | 530 | 531 | 532 | 533 | 534 | Default 535 | 536 | 537 | 538 | 539 | 540 | 541 | Left to Right 542 | 543 | 544 | 545 | 546 | 547 | 548 | Right to Left 549 | 550 | 551 | 552 | 553 | 554 | 555 | 556 | 557 | 558 | 559 | 560 | 561 | 562 | 563 | 564 | 565 | 566 | 567 | 568 | 569 | 570 | 571 | 572 | 573 | 574 | 575 | 576 | 577 | 578 | 579 | 580 | 581 | 582 | 583 | 584 | 585 | 586 | 587 | 588 | 589 | 590 | 591 | 592 | 593 | 594 | 595 | 596 | 597 | 598 | 599 | 600 | 601 | 602 | 603 | 604 | 605 | 606 | 607 | 608 | 609 | 610 | 611 | 612 | 613 | 614 | 615 | 616 | 617 | 618 | 619 | 620 | 621 | 622 | 623 | 624 | 625 | 626 | 627 | 628 | 629 | 630 | 631 | 632 | 633 | 634 | 635 | 636 | 637 | 638 | 639 | 640 | 641 | 642 | 643 | 644 | 645 | 646 | 647 | 648 | 649 | 650 | 651 | 652 | 653 | 654 | 655 | 656 | 657 | 658 | 659 | 660 | 661 | 662 | 663 | 664 | 665 | 666 | 667 | 668 | 669 | 670 | 671 | 672 | 673 | 674 | 675 | 676 | 677 | 678 | 679 | 680 | 681 | 682 | 683 | 684 | 695 | 706 | 717 | 728 | 739 | 740 | 741 | 742 | 743 | 744 | 745 | 746 | 747 | 748 | 749 | 750 | 751 | 752 | 753 | 754 | 755 | 756 | 757 | 758 | 759 | 760 | 761 | 762 | 763 | 764 | 765 | 766 | 767 | 768 | 769 | 770 | 771 | 772 | 773 | 774 | 775 | 776 | 777 | 778 | 779 | 780 | 781 | 782 | 783 | 784 | 785 | 786 | 787 | 788 | 789 | 790 | 791 | 792 | 793 | 794 | 795 | 796 | 797 | 798 | 799 | 800 | 801 | 802 | 803 | 804 | 805 | 806 | 807 | 808 | 809 | 810 | 811 | 812 | 813 | 824 | 825 | 826 | 827 | 828 | 829 | 830 | 831 | 832 | 833 | 834 | 835 | 836 | 837 | 838 | 839 | 840 | 841 | 842 | 843 | 844 | 845 | 846 | 847 | 848 | 849 | 850 | 851 | 852 | 853 | 854 | 855 | 856 | 857 | 858 | 859 | 860 | 861 | 862 | 863 | 864 | 865 | 866 | 867 | 868 | 869 | 870 | 871 | 872 | -------------------------------------------------------------------------------- /KSTabView/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "mac", 5 | "size" : "16x16", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "mac", 10 | "size" : "16x16", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "mac", 15 | "size" : "32x32", 16 | "scale" : "1x" 17 | }, 18 | { 19 | "idiom" : "mac", 20 | "size" : "32x32", 21 | "scale" : "2x" 22 | }, 23 | { 24 | "idiom" : "mac", 25 | "size" : "128x128", 26 | "scale" : "1x" 27 | }, 28 | { 29 | "idiom" : "mac", 30 | "size" : "128x128", 31 | "scale" : "2x" 32 | }, 33 | { 34 | "idiom" : "mac", 35 | "size" : "256x256", 36 | "scale" : "1x" 37 | }, 38 | { 39 | "idiom" : "mac", 40 | "size" : "256x256", 41 | "scale" : "2x" 42 | }, 43 | { 44 | "idiom" : "mac", 45 | "size" : "512x512", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "mac", 50 | "size" : "512x512", 51 | "scale" : "2x" 52 | } 53 | ], 54 | "info" : { 55 | "version" : 1, 56 | "author" : "xcode" 57 | } 58 | } -------------------------------------------------------------------------------- /KSTabView/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | $(PRODUCT_NAME) 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | $(MACOSX_DEPLOYMENT_TARGET) 27 | NSHumanReadableCopyright 28 | Copyright © 2015 com.kaunteya. All rights reserved. 29 | NSMainStoryboardFile 30 | Main 31 | NSPrincipalClass 32 | NSApplication 33 | 34 | 35 | -------------------------------------------------------------------------------- /KSTabView/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // KSTabView 4 | // 5 | // Created by Kaunteya Suryawanshi on 13/06/15. 6 | // Copyright (c) 2015 com.kaunteya. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | 11 | class ViewController: NSViewController { 12 | 13 | @IBOutlet weak var tabView: KSTabView! 14 | 15 | @IBAction func selectionTypeChanged(sender: NSSegmentedControl) { 16 | tabView.selectionType = KSTabView.SelectionType(rawValue: sender.selectedSegment)! 17 | } 18 | 19 | @IBAction func actionOccured(sender: NSString?) { 20 | print("\(sender) pressed") 21 | } 22 | 23 | @IBAction func addLeft(sender: AnyObject) { 24 | tabView.removeLeftButtons() 25 | tabView.pushButtonLeft("reload", title: "Reload") 26 | tabView.pushButtonLeft("find", title: "Find") 27 | } 28 | 29 | @IBAction func leftClean(sender: AnyObject) { 30 | tabView.removeLeftButtons() 31 | } 32 | 33 | @IBAction func addRight(sender: NSSegmentedControl) { 34 | tabView.rightImagePosition = NSCellImagePosition(rawValue: UInt(sender.selectedSegment))! 35 | 36 | tabView.removeRightButtons() 37 | .pushButtonRight("facebook", title: "Facebook", image: NSImage(named: "facebook.png")!, alternateImage: NSImage(named: "altFacebook.png")!) 38 | .pushButtonRight("google", title: "Google", image: NSImage(named: "google.png")!, alternateImage: nil) 39 | .pushButtonRight("instagram", title: "Instagram", image: NSImage(named: "instagram.png")!, alternateImage: nil) 40 | .pushButtonRight("twitter", title: "Twitter", image: NSImage(named: "twitter.png")!, alternateImage: nil).selectedButtons = ["instagram"] 41 | 42 | } 43 | 44 | @IBAction func rightClean(sender: AnyObject) { 45 | tabView.removeRightButtons() 46 | } 47 | 48 | @IBAction func selectMultiple(sender: NSButton) { 49 | tabView.selectedButtons = ["google", "twitter", "reload"] 50 | } 51 | 52 | @IBAction func selectOne(sender: NSButton) { 53 | tabView.selectedButtons = ["instagram", ] 54 | } 55 | 56 | @IBAction func clearSelection(sender: NSButton) { 57 | tabView.selectedButtons = [] 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /KSTabView/images/altFacebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/KSTabView/images/altFacebook.png -------------------------------------------------------------------------------- /KSTabView/images/facebook.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/KSTabView/images/facebook.png -------------------------------------------------------------------------------- /KSTabView/images/google.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/KSTabView/images/google.png -------------------------------------------------------------------------------- /KSTabView/images/instagram.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/KSTabView/images/instagram.png -------------------------------------------------------------------------------- /KSTabView/images/twitter.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/KSTabView/images/twitter.png -------------------------------------------------------------------------------- /KSTabViewTests/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 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /KSTabViewTests/KSTabViewTests.swift: -------------------------------------------------------------------------------- 1 | // 2 | // KSTabViewTests.swift 3 | // KSTabViewTests 4 | // 5 | // Created by Kaunteya Suryawanshi on 13/06/15. 6 | // Copyright (c) 2015 com.kaunteya. All rights reserved. 7 | // 8 | 9 | import Cocoa 10 | import XCTest 11 | 12 | class KSTabViewTests: XCTestCase { 13 | 14 | override func setUp() { 15 | super.setUp() 16 | // Put setup code here. This method is called before the invocation of each test method in the class. 17 | } 18 | 19 | override func tearDown() { 20 | // Put teardown code here. This method is called after the invocation of each test method in the class. 21 | super.tearDown() 22 | } 23 | 24 | func testExample() { 25 | // This is an example of a functional test case. 26 | XCTAssert(true, "Pass") 27 | } 28 | 29 | func testPerformanceExample() { 30 | // This is an example of a performance test case. 31 | self.measureBlock() { 32 | // Put the code you want to measure the time of here. 33 | } 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 kaunteya 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 all 13 | 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 THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #KSTabView 2 | 3 | `KSTabView` is simple and lightweight TabView for Mac OSX implemented in Swift 4 | ![](./demo.png) 5 | 6 | ## Features 7 | - Complete autolayout support 8 | - All configurations are IBInspecatable 9 | - Simple and lightweight 10 | 11 | ## Requirements 12 | - Mac OS X 10.10+ 13 | - Xcode 6.3 14 | 15 | ## Usage 16 | #### Setup 17 | Drag `KSTabView.swift` to you project. 18 | 19 | In IB, drag a Custom View from Object Library. Set Custom Class to KSTabView 20 | 21 | Drag IBOutlet to ViewController 22 | ```swift 23 | @IBOutlet weak var tabView: KSTabView! 24 | ``` 25 | #### Adding buttons 26 | Buttons can be pushed either left or right Aligned 27 | ```swift 28 | tabView.pushButtonLeft("Reload", identifier: "reload") // Adds Button with title "Reload" and identifier "reload" aligned Left 29 | tabView.pushButtonRight("Jump", identifier: "jump") 30 | ``` 31 | Identifier is must, as the action event will receive this identifier String as an argument 32 | 33 | #### Button Actions 34 | Handling the button clicks is as easy as creating an IBAction in view controller 35 | ```swift 36 | @IBAction func actionOccured(sender: NSString?) { 37 | println("\(sender) pressed") // Prints the identifier of button that is clicked 38 | } 39 | 40 | ``` 41 | #### Removing buttons 42 | Buttons can be removed, so that new ones can be added 43 | ```swift 44 | tabView.removeLeftButtons() //Removes all the Left aligned buttons 45 | tabView.removeRightButtons() //Removes all the Right aligned buttons 46 | ``` 47 | #### Modes of operation 48 | KSTabview has 3 modes of operation viz `None`, `One`, `Any` 49 | ```swift 50 | tabView.selectionType = .None // No selection happens.(Only action triggers) 51 | tabView.selectionType = .One // Only the latest selection stays 52 | tabView.selectionType = .Any // Multiple buttons can be selected 53 | ``` 54 | #### Chaining 55 | Methods that are not intended to return anything return self, to facilitate method chaining 56 | ```swift 57 | tabView.removeRightButtons() 58 | .pushButtonRight("Help", identifier: "help") 59 | .pushButtonRight("Modify", identifier: "modify") 60 | .pushButtonRight("Delete", identifier: "delete") 61 | .pushButtonRight("New", identifier: "new").selectedButtons = ["modify"] 62 | ``` 63 | ## Todo 64 | - Allow add buttons from Interface Builder 65 | - Documentation 66 | - Support for buttons with Image 67 | -------------------------------------------------------------------------------- /demo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kaunteya/KSTabView/568e7954926788941beb472fa72f07f8e0d9f597/demo.png --------------------------------------------------------------------------------