├── DPSegmentedControl └── DPSegmentedControl.swift ├── LICENSE ├── README.md ├── Segmented.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── dwipp.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── dwipp.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── Segmented.xcscheme │ └── xcschememanagement.plist └── Segmented ├── AppDelegate.swift ├── Assets.xcassets ├── AppIcon.appiconset │ └── Contents.json ├── Contents.json ├── flat_gray.imageset │ ├── Contents.json │ ├── iconmoodnormal_disable.png │ ├── iconmoodnormal_disable@2x.png │ └── iconmoodnormal_disable@3x.png ├── flat_white.imageset │ ├── Contents.json │ ├── iconmoodnormal_enable.png │ ├── iconmoodnormal_enable@2x.png │ └── iconmoodnormal_enable@3x.png ├── happy_gray.imageset │ ├── Contents.json │ ├── iconmoodhappy_disable.png │ ├── iconmoodhappy_disable@2x.png │ └── iconmoodhappy_disable@3x.png ├── happy_white.imageset │ ├── Contents.json │ ├── iconmoodhappy_enable.png │ ├── iconmoodhappy_enable@2x.png │ └── iconmoodhappy_enable@3x.png ├── sad_gray.imageset │ ├── Contents.json │ ├── iconmoodsad_disable.png │ ├── iconmoodsad_disable@2x.png │ └── iconmoodsad_disable@3x.png └── sad_white.imageset │ ├── Contents.json │ ├── iconmoodsad_enable.png │ ├── iconmoodsad_enable@2x.png │ └── iconmoodsad_enable@3x.png ├── Base.lproj ├── LaunchScreen.storyboard └── Main.storyboard ├── Info.plist └── ViewController.swift /DPSegmentedControl/DPSegmentedControl.swift: -------------------------------------------------------------------------------- 1 | // 2 | // SegmentedControl.swift 3 | // Segmented 4 | // 5 | // Created by Dwi Permana Putra on 5/30/16. 6 | // Copyright © 2016 Dwi Permana Putra. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | enum ComponentOrientation { 12 | case TopDown 13 | case LeftRight 14 | } 15 | 16 | class DPSegmentedControl:UIControl { 17 | 18 | private var componentOrientation: ComponentOrientation = ComponentOrientation.LeftRight 19 | 20 | private var labels = [UILabel]() 21 | private var icons = [UIImageView]() 22 | private var selectedLabel = UILabel() 23 | 24 | private var img_icon = UIImageView() 25 | private var selected_img_icon = UIImageView() 26 | 27 | private var withIcon:Bool = true 28 | 29 | private func setOrientation(orientation orientation:ComponentOrientation){ 30 | switch orientation { 31 | case .LeftRight: 32 | componentOrientation = ComponentOrientation.LeftRight 33 | case .TopDown : 34 | componentOrientation = ComponentOrientation.TopDown 35 | } 36 | } 37 | 38 | private var thumbColor: UIColor = UIColor.whiteColor() { 39 | didSet{ 40 | setThumbColor() 41 | } 42 | } 43 | 44 | private func setThumbColor(){ 45 | thumbView.backgroundColor = thumbColor 46 | } 47 | 48 | private var textColor: UIColor = UIColor.whiteColor() 49 | 50 | private func setTextColor(){ 51 | for i in 0.. CGRect { 112 | let width = self.bounds.width/CGFloat(items.count) 113 | let height = self.bounds.height 114 | let iconX = getIconX(width, textWidth: evaluateStringWidth(text)) 115 | let x = width*CGFloat(index-1) 116 | 117 | switch orientation { 118 | case .LeftRight: 119 | let evaluateIconX = x + iconX 120 | let iconRect = CGRectMake(evaluateIconX, 0, 16, height) 121 | return iconRect 122 | case .TopDown: 123 | let centre:CGFloat = x + ((width-16)/2) 124 | let iconRect = CGRectMake(centre, 7, 16, 16) 125 | return iconRect 126 | } 127 | } 128 | 129 | private func getTextFrameByOrintation(orientation:ComponentOrientation, text:String, index:Int) -> CGRect { 130 | let height = self.bounds.height 131 | let width = self.bounds.width/CGFloat(items.count) 132 | let textX = getTextX(width, textWidth: evaluateStringWidth(text)) 133 | let xPosition = CGFloat(index) * width 134 | let evaluateTextX = xPosition + textX 135 | 136 | switch orientation { 137 | case .LeftRight: 138 | let textRect = CGRectMake(evaluateTextX, 0, width, height) 139 | return textRect 140 | case .TopDown: 141 | let centre = evaluateTextX - 13 142 | let textRect:CGRect? 143 | if withIcon { 144 | textRect = CGRectMake(centre, 18, width, 25) 145 | }else { 146 | textRect = CGRectMake(centre, 0, width, height) 147 | } 148 | return textRect! 149 | } 150 | } 151 | 152 | 153 | private func setupView(){ 154 | layer.cornerRadius = 5 155 | setupLabels() 156 | insertSubview(thumbView, atIndex: 0) 157 | } 158 | 159 | private func setupLabels(){ 160 | 161 | 162 | for label in labels { 163 | label.removeFromSuperview() 164 | } 165 | labels.removeAll(keepCapacity: true) 166 | 167 | for index in 1...items.count { 168 | 169 | 170 | let view = UIView.init(frame: CGRectZero) 171 | 172 | let label = UILabel(frame: CGRectZero) 173 | label.text = items[index-1] 174 | label.textColor = textColor 175 | view.addSubview(label) 176 | labels.append(label) 177 | 178 | let text = items[index-1] 179 | 180 | if withIcon { 181 | self.img_icon = UIImageView(frame: getIconFrameByOrientation(self.componentOrientation, index: index, text: text)) 182 | self.img_icon.contentMode = .ScaleAspectFit 183 | self.img_icon.image = icon[index-1] 184 | 185 | view.addSubview(self.img_icon) 186 | icons.append(self.img_icon) 187 | } 188 | 189 | self.addSubview(view) 190 | 191 | } 192 | setTextColor() 193 | 194 | } 195 | 196 | private func getIconX(itemWidth:CGFloat, textWidth:CGFloat) -> CGFloat{ 197 | let iconWidth:CGFloat = 16.0 198 | let avg = (iconWidth + textWidth) 199 | let space:CGFloat = (itemWidth - avg)/2 200 | 201 | return space + 2 202 | } 203 | 204 | private func getTextX(itemWidth:CGFloat, textWidth:CGFloat) -> CGFloat { 205 | let iconWidth:CGFloat = 16.0 206 | let avg = (iconWidth + textWidth) 207 | let space:CGFloat = (itemWidth - avg)/2 208 | 209 | let x = space + iconWidth 210 | 211 | return x + 8 212 | } 213 | 214 | internal override func layoutSubviews() { 215 | super.layoutSubviews() 216 | 217 | var selectedFrame = self.bounds 218 | let newWidth = CGRectGetWidth(selectedFrame) / CGFloat(items.count) 219 | selectedFrame.size.width = newWidth 220 | 221 | selectedFrame.origin.x = selectedFrame.origin.x + 4 222 | selectedFrame.origin.y = selectedFrame.origin.y + 4 223 | selectedFrame.size.width = selectedFrame.width - 8 224 | selectedFrame.size.height = selectedFrame.height - 8 225 | 226 | 227 | if selectedIndex > 0 { 228 | setTextColor() 229 | setSelectedTextColor() 230 | thumbView.frame = setDefaultSelectionPoint(selectedIndex) 231 | }else { 232 | thumbView.frame = selectedFrame 233 | } 234 | 235 | thumbView.backgroundColor = thumbColor 236 | thumbView.layer.cornerRadius = 5 237 | 238 | 239 | for index in 0...labels.count - 1 { 240 | let label = labels[index] 241 | 242 | let text = items[index] 243 | 244 | 245 | label.frame = getTextFrameByOrintation(self.componentOrientation, text: text, index: index) 246 | 247 | } 248 | } 249 | 250 | private func evaluateStringWidth (textToEvaluate: String) -> CGFloat{ 251 | let lbl = UILabel(frame: CGRectZero) 252 | lbl.text = textToEvaluate 253 | lbl.sizeToFit() 254 | 255 | return lbl.frame.width 256 | } 257 | 258 | internal override func beginTrackingWithTouch(touch: UITouch, withEvent event: UIEvent?) -> Bool { 259 | let location = touch.locationInView(self) 260 | 261 | let labelWidth = self.bounds.width / CGFloat(items.count) 262 | 263 | var calculatedIndex : Int? 264 | for (index, item) in labels.enumerate() { 265 | 266 | let text = items[index] 267 | 268 | let iconX = getIconX(labelWidth, textWidth: evaluateStringWidth(text)) 269 | 270 | let frame = CGRectMake(item.frame.origin.x - (iconX*2), 0, item.frame.width, self.bounds.height) 271 | 272 | if frame.contains(location){ 273 | calculatedIndex = index 274 | }else{ 275 | item.textColor = textColor 276 | if withIcon { 277 | icons[index].image = icon[index] 278 | } 279 | 280 | } 281 | } 282 | 283 | if calculatedIndex != nil { 284 | selectedIndex = calculatedIndex! 285 | sendActionsForControlEvents(.ValueChanged) 286 | } 287 | return false 288 | } 289 | 290 | private func displayNewSelectedIndex(){ 291 | selectedLabel = labels[selectedIndex] 292 | selectedLabel.textColor = selectedTextColor 293 | 294 | if withIcon { 295 | selected_img_icon = icons[selectedIndex] 296 | selected_img_icon.image = selected_icon[selectedIndex] 297 | } 298 | 299 | 300 | let text = items[selectedIndex] 301 | 302 | let labelWidth = self.bounds.width / CGFloat(items.count) 303 | let iconX = getTextX(labelWidth, textWidth: evaluateStringWidth(text)) 304 | 305 | UIView.animateWithDuration(0.5, delay: 0.0, usingSpringWithDamping: 0.7, initialSpringVelocity: 0.8, options: [], animations: { 306 | 307 | var labelFrame = self.selectedLabel.bounds 308 | 309 | print("selectedLabel: \(self.selectedLabel.frame.origin.x)") 310 | 311 | if self.componentOrientation == ComponentOrientation.TopDown { 312 | labelFrame.origin.x = self.selectedLabel.frame.origin.x - iconX + 4 + 13 313 | }else{ 314 | labelFrame.origin.x = self.selectedLabel.frame.origin.x - iconX + 4 315 | } 316 | 317 | labelFrame.origin.y = 4 318 | labelFrame.size.width = self.selectedLabel.frame.width - 8 319 | labelFrame.size.height = self.bounds.height - 8 320 | 321 | 322 | self.thumbView.frame = self.setDefaultSelectionPoint(self.selectedIndex) 323 | 324 | }, completion: nil) 325 | 326 | 327 | } 328 | 329 | private func setDefaultSelectionPoint(index:Int) -> CGRect{ 330 | let selectedLabel = labels[index] 331 | var selectedFrame = selectedLabel.bounds 332 | 333 | if withIcon { 334 | selected_img_icon = icons[selectedIndex] 335 | selected_img_icon.image = selected_icon[selectedIndex] 336 | } 337 | 338 | let text = items[selectedIndex] 339 | let labelWidth = self.bounds.width / CGFloat(items.count) 340 | let iconX = getTextX(labelWidth, textWidth: evaluateStringWidth(text)) 341 | 342 | if self.componentOrientation == ComponentOrientation.TopDown { 343 | selectedFrame.origin.x = self.selectedLabel.frame.origin.x - iconX + 4 + 13 344 | }else{ 345 | selectedFrame.origin.x = self.selectedLabel.frame.origin.x - iconX + 4 346 | } 347 | selectedFrame.origin.y = 4 348 | selectedFrame.size.width = self.selectedLabel.frame.width - 8 349 | selectedFrame.size.height = self.bounds.height - 8 350 | return selectedFrame 351 | } 352 | 353 | 354 | } 355 | 356 | 357 | 358 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 Dwi Permana Putra (dwi.putra@icloud.com) 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DPSegmentedControl 2 | 3 | This is a custom Segmented Control with icon and text on every segment. 4 | DPSegmentedControl is tested on iOS 10.0 5 | This awesome library is wrote on swift 3 6 | 7 | 8 | ## Usage 9 | 10 | #### Initialization segmented control with icon 11 | ``` swift 12 | let segmentedControl = DPSegmentedControl.init( 13 | FrameWithIcon: CGRect(x: 8, y: 50, width: view.frame.width - 16, height: 44), 14 | items: ["Happy", "Normal", "Sad"], 15 | icons: [UIImage(named: "happy_gray")!, UIImage(named: "flat_gray")!, UIImage(named: "sad_gray")!], 16 | selectedIcons: [UIImage(named: "happy_white")!, UIImage(named: "flat_white")!, UIImage(named: "sad_white")!], 17 | backgroundColor: UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1), 18 | thumbColor: UIColor.init(hex: "#54C3EF"), 19 | textColor: UIColor(hex: "#808080"), 20 | selectedTextColor: UIColor(hex: "#FFFFFF"), 21 | orientation: ComponentOrientation.LeftRight) 22 | ``` 23 | 24 | #### Initialization segmented control without icon 25 | ``` swift 26 | let segmentedControl = DPSegmentedControl.init( 27 | FrameWithoutIcon: CGRect(x: 8, y: 50, width: view.frame.width - 16, height: 44), 28 | items: ["Happy", "Normal", "Sad"], 29 | backgroundColor: UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1), 30 | thumbColor: UIColor.init(hex: "#54C3EF"), 31 | textColor: UIColor(hex: "#808080"), 32 | selectedTextColor: UIColor(hex: "#FFFFFF")) 33 | ``` 34 | 35 | 36 | ``` swift 37 | // To get the changed value event, set it manually on your view controller 38 | segmentedControl.addTarget(self, action: #selector(orderTypeChanged), for: .valueChanged) 39 | 40 | // You need to add DPSegmnetedControl to container 41 | self.view.addSubview(segmentedControl) 42 | 43 | // You could set the selected index. Default is 0 44 | segmentedControl.selectedIndex = 1 45 | ``` 46 | 47 | ## Sample 48 | 49 | ![gif](http://i.giphy.com/iZvJT92KGkeiI.gif) 50 | 51 | [This is the video sample](https://youtu.be/PaVUNysxyf4) 52 | 53 | ## Installation 54 | 55 | Manual installation. Just copy DPSegmentedControl folder to your project. 56 | Will be available on cocoapods soon. 57 | 58 | ## License 59 | 60 | DPSegmentedControl is released under the MIT license. See LICENSE for details. 61 | 62 | -------------------------------------------------------------------------------- /Segmented.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 967DCF0C1D200F570054C6DF /* DPSegmentedControl.swift in Sources */ = {isa = PBXBuildFile; fileRef = 967DCF0B1D200F570054C6DF /* DPSegmentedControl.swift */; }; 11 | 96EC3F2F1CFC2C8E00BD8BA7 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96EC3F2E1CFC2C8E00BD8BA7 /* AppDelegate.swift */; }; 12 | 96EC3F311CFC2C8E00BD8BA7 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 96EC3F301CFC2C8E00BD8BA7 /* ViewController.swift */; }; 13 | 96EC3F341CFC2C8E00BD8BA7 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96EC3F321CFC2C8E00BD8BA7 /* Main.storyboard */; }; 14 | 96EC3F361CFC2C8E00BD8BA7 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 96EC3F351CFC2C8E00BD8BA7 /* Assets.xcassets */; }; 15 | 96EC3F391CFC2C8E00BD8BA7 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 96EC3F371CFC2C8E00BD8BA7 /* LaunchScreen.storyboard */; }; 16 | /* End PBXBuildFile section */ 17 | 18 | /* Begin PBXFileReference section */ 19 | 967DCF0B1D200F570054C6DF /* DPSegmentedControl.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPSegmentedControl.swift; sourceTree = ""; }; 20 | 96EC3F2B1CFC2C8E00BD8BA7 /* Segmented.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Segmented.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | 96EC3F2E1CFC2C8E00BD8BA7 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | 96EC3F301CFC2C8E00BD8BA7 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | 96EC3F331CFC2C8E00BD8BA7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | 96EC3F351CFC2C8E00BD8BA7 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | 96EC3F381CFC2C8E00BD8BA7 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | 96EC3F3A1CFC2C8E00BD8BA7 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | /* End PBXFileReference section */ 28 | 29 | /* Begin PBXFrameworksBuildPhase section */ 30 | 96EC3F281CFC2C8E00BD8BA7 /* Frameworks */ = { 31 | isa = PBXFrameworksBuildPhase; 32 | buildActionMask = 2147483647; 33 | files = ( 34 | ); 35 | runOnlyForDeploymentPostprocessing = 0; 36 | }; 37 | /* End PBXFrameworksBuildPhase section */ 38 | 39 | /* Begin PBXGroup section */ 40 | 967DCF0A1D200F570054C6DF /* DPSegmentedControl */ = { 41 | isa = PBXGroup; 42 | children = ( 43 | 967DCF0B1D200F570054C6DF /* DPSegmentedControl.swift */, 44 | ); 45 | path = DPSegmentedControl; 46 | sourceTree = SOURCE_ROOT; 47 | }; 48 | 96EC3F221CFC2C8E00BD8BA7 = { 49 | isa = PBXGroup; 50 | children = ( 51 | 96EC3F2D1CFC2C8E00BD8BA7 /* Segmented */, 52 | 96EC3F2C1CFC2C8E00BD8BA7 /* Products */, 53 | ); 54 | sourceTree = ""; 55 | }; 56 | 96EC3F2C1CFC2C8E00BD8BA7 /* Products */ = { 57 | isa = PBXGroup; 58 | children = ( 59 | 96EC3F2B1CFC2C8E00BD8BA7 /* Segmented.app */, 60 | ); 61 | name = Products; 62 | sourceTree = ""; 63 | }; 64 | 96EC3F2D1CFC2C8E00BD8BA7 /* Segmented */ = { 65 | isa = PBXGroup; 66 | children = ( 67 | 967DCF0A1D200F570054C6DF /* DPSegmentedControl */, 68 | 96EC3F2E1CFC2C8E00BD8BA7 /* AppDelegate.swift */, 69 | 96EC3F301CFC2C8E00BD8BA7 /* ViewController.swift */, 70 | 96EC3F321CFC2C8E00BD8BA7 /* Main.storyboard */, 71 | 96EC3F351CFC2C8E00BD8BA7 /* Assets.xcassets */, 72 | 96EC3F371CFC2C8E00BD8BA7 /* LaunchScreen.storyboard */, 73 | 96EC3F3A1CFC2C8E00BD8BA7 /* Info.plist */, 74 | ); 75 | path = Segmented; 76 | sourceTree = ""; 77 | }; 78 | /* End PBXGroup section */ 79 | 80 | /* Begin PBXNativeTarget section */ 81 | 96EC3F2A1CFC2C8E00BD8BA7 /* Segmented */ = { 82 | isa = PBXNativeTarget; 83 | buildConfigurationList = 96EC3F3D1CFC2C8E00BD8BA7 /* Build configuration list for PBXNativeTarget "Segmented" */; 84 | buildPhases = ( 85 | 96EC3F271CFC2C8E00BD8BA7 /* Sources */, 86 | 96EC3F281CFC2C8E00BD8BA7 /* Frameworks */, 87 | 96EC3F291CFC2C8E00BD8BA7 /* Resources */, 88 | ); 89 | buildRules = ( 90 | ); 91 | dependencies = ( 92 | ); 93 | name = Segmented; 94 | productName = Segmented; 95 | productReference = 96EC3F2B1CFC2C8E00BD8BA7 /* Segmented.app */; 96 | productType = "com.apple.product-type.application"; 97 | }; 98 | /* End PBXNativeTarget section */ 99 | 100 | /* Begin PBXProject section */ 101 | 96EC3F231CFC2C8E00BD8BA7 /* Project object */ = { 102 | isa = PBXProject; 103 | attributes = { 104 | LastSwiftUpdateCheck = 0730; 105 | LastUpgradeCheck = 0730; 106 | ORGANIZATIONNAME = "Dwi Permana Putra"; 107 | TargetAttributes = { 108 | 96EC3F2A1CFC2C8E00BD8BA7 = { 109 | CreatedOnToolsVersion = 7.3.1; 110 | DevelopmentTeam = 2RL4G4B6A8; 111 | }; 112 | }; 113 | }; 114 | buildConfigurationList = 96EC3F261CFC2C8E00BD8BA7 /* Build configuration list for PBXProject "Segmented" */; 115 | compatibilityVersion = "Xcode 3.2"; 116 | developmentRegion = English; 117 | hasScannedForEncodings = 0; 118 | knownRegions = ( 119 | en, 120 | Base, 121 | ); 122 | mainGroup = 96EC3F221CFC2C8E00BD8BA7; 123 | productRefGroup = 96EC3F2C1CFC2C8E00BD8BA7 /* Products */; 124 | projectDirPath = ""; 125 | projectRoot = ""; 126 | targets = ( 127 | 96EC3F2A1CFC2C8E00BD8BA7 /* Segmented */, 128 | ); 129 | }; 130 | /* End PBXProject section */ 131 | 132 | /* Begin PBXResourcesBuildPhase section */ 133 | 96EC3F291CFC2C8E00BD8BA7 /* Resources */ = { 134 | isa = PBXResourcesBuildPhase; 135 | buildActionMask = 2147483647; 136 | files = ( 137 | 96EC3F391CFC2C8E00BD8BA7 /* LaunchScreen.storyboard in Resources */, 138 | 96EC3F361CFC2C8E00BD8BA7 /* Assets.xcassets in Resources */, 139 | 96EC3F341CFC2C8E00BD8BA7 /* Main.storyboard in Resources */, 140 | ); 141 | runOnlyForDeploymentPostprocessing = 0; 142 | }; 143 | /* End PBXResourcesBuildPhase section */ 144 | 145 | /* Begin PBXSourcesBuildPhase section */ 146 | 96EC3F271CFC2C8E00BD8BA7 /* Sources */ = { 147 | isa = PBXSourcesBuildPhase; 148 | buildActionMask = 2147483647; 149 | files = ( 150 | 96EC3F311CFC2C8E00BD8BA7 /* ViewController.swift in Sources */, 151 | 96EC3F2F1CFC2C8E00BD8BA7 /* AppDelegate.swift in Sources */, 152 | 967DCF0C1D200F570054C6DF /* DPSegmentedControl.swift in Sources */, 153 | ); 154 | runOnlyForDeploymentPostprocessing = 0; 155 | }; 156 | /* End PBXSourcesBuildPhase section */ 157 | 158 | /* Begin PBXVariantGroup section */ 159 | 96EC3F321CFC2C8E00BD8BA7 /* Main.storyboard */ = { 160 | isa = PBXVariantGroup; 161 | children = ( 162 | 96EC3F331CFC2C8E00BD8BA7 /* Base */, 163 | ); 164 | name = Main.storyboard; 165 | sourceTree = ""; 166 | }; 167 | 96EC3F371CFC2C8E00BD8BA7 /* LaunchScreen.storyboard */ = { 168 | isa = PBXVariantGroup; 169 | children = ( 170 | 96EC3F381CFC2C8E00BD8BA7 /* Base */, 171 | ); 172 | name = LaunchScreen.storyboard; 173 | sourceTree = ""; 174 | }; 175 | /* End PBXVariantGroup section */ 176 | 177 | /* Begin XCBuildConfiguration section */ 178 | 96EC3F3B1CFC2C8E00BD8BA7 /* Debug */ = { 179 | isa = XCBuildConfiguration; 180 | buildSettings = { 181 | ALWAYS_SEARCH_USER_PATHS = NO; 182 | CLANG_ANALYZER_NONNULL = YES; 183 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 184 | CLANG_CXX_LIBRARY = "libc++"; 185 | CLANG_ENABLE_MODULES = YES; 186 | CLANG_ENABLE_OBJC_ARC = YES; 187 | CLANG_WARN_BOOL_CONVERSION = YES; 188 | CLANG_WARN_CONSTANT_CONVERSION = YES; 189 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 190 | CLANG_WARN_EMPTY_BODY = YES; 191 | CLANG_WARN_ENUM_CONVERSION = YES; 192 | CLANG_WARN_INT_CONVERSION = YES; 193 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 194 | CLANG_WARN_UNREACHABLE_CODE = YES; 195 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 196 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 197 | COPY_PHASE_STRIP = NO; 198 | DEBUG_INFORMATION_FORMAT = dwarf; 199 | ENABLE_STRICT_OBJC_MSGSEND = YES; 200 | ENABLE_TESTABILITY = YES; 201 | GCC_C_LANGUAGE_STANDARD = gnu99; 202 | GCC_DYNAMIC_NO_PIC = NO; 203 | GCC_NO_COMMON_BLOCKS = YES; 204 | GCC_OPTIMIZATION_LEVEL = 0; 205 | GCC_PREPROCESSOR_DEFINITIONS = ( 206 | "DEBUG=1", 207 | "$(inherited)", 208 | ); 209 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 210 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 211 | GCC_WARN_UNDECLARED_SELECTOR = YES; 212 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 213 | GCC_WARN_UNUSED_FUNCTION = YES; 214 | GCC_WARN_UNUSED_VARIABLE = YES; 215 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 216 | MTL_ENABLE_DEBUG_INFO = YES; 217 | ONLY_ACTIVE_ARCH = YES; 218 | SDKROOT = iphoneos; 219 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 220 | }; 221 | name = Debug; 222 | }; 223 | 96EC3F3C1CFC2C8E00BD8BA7 /* Release */ = { 224 | isa = XCBuildConfiguration; 225 | buildSettings = { 226 | ALWAYS_SEARCH_USER_PATHS = NO; 227 | CLANG_ANALYZER_NONNULL = YES; 228 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 229 | CLANG_CXX_LIBRARY = "libc++"; 230 | CLANG_ENABLE_MODULES = YES; 231 | CLANG_ENABLE_OBJC_ARC = YES; 232 | CLANG_WARN_BOOL_CONVERSION = YES; 233 | CLANG_WARN_CONSTANT_CONVERSION = YES; 234 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 235 | CLANG_WARN_EMPTY_BODY = YES; 236 | CLANG_WARN_ENUM_CONVERSION = YES; 237 | CLANG_WARN_INT_CONVERSION = YES; 238 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 239 | CLANG_WARN_UNREACHABLE_CODE = YES; 240 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 241 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 242 | COPY_PHASE_STRIP = NO; 243 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 244 | ENABLE_NS_ASSERTIONS = NO; 245 | ENABLE_STRICT_OBJC_MSGSEND = YES; 246 | GCC_C_LANGUAGE_STANDARD = gnu99; 247 | GCC_NO_COMMON_BLOCKS = YES; 248 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 249 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 250 | GCC_WARN_UNDECLARED_SELECTOR = YES; 251 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 252 | GCC_WARN_UNUSED_FUNCTION = YES; 253 | GCC_WARN_UNUSED_VARIABLE = YES; 254 | IPHONEOS_DEPLOYMENT_TARGET = 9.3; 255 | MTL_ENABLE_DEBUG_INFO = NO; 256 | SDKROOT = iphoneos; 257 | VALIDATE_PRODUCT = YES; 258 | }; 259 | name = Release; 260 | }; 261 | 96EC3F3E1CFC2C8E00BD8BA7 /* Debug */ = { 262 | isa = XCBuildConfiguration; 263 | buildSettings = { 264 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 265 | INFOPLIST_FILE = Segmented/Info.plist; 266 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 267 | PRODUCT_BUNDLE_IDENTIFIER = com.dwipp.Segmented; 268 | PRODUCT_NAME = "$(TARGET_NAME)"; 269 | }; 270 | name = Debug; 271 | }; 272 | 96EC3F3F1CFC2C8E00BD8BA7 /* Release */ = { 273 | isa = XCBuildConfiguration; 274 | buildSettings = { 275 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 276 | INFOPLIST_FILE = Segmented/Info.plist; 277 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 278 | PRODUCT_BUNDLE_IDENTIFIER = com.dwipp.Segmented; 279 | PRODUCT_NAME = "$(TARGET_NAME)"; 280 | }; 281 | name = Release; 282 | }; 283 | /* End XCBuildConfiguration section */ 284 | 285 | /* Begin XCConfigurationList section */ 286 | 96EC3F261CFC2C8E00BD8BA7 /* Build configuration list for PBXProject "Segmented" */ = { 287 | isa = XCConfigurationList; 288 | buildConfigurations = ( 289 | 96EC3F3B1CFC2C8E00BD8BA7 /* Debug */, 290 | 96EC3F3C1CFC2C8E00BD8BA7 /* Release */, 291 | ); 292 | defaultConfigurationIsVisible = 0; 293 | defaultConfigurationName = Release; 294 | }; 295 | 96EC3F3D1CFC2C8E00BD8BA7 /* Build configuration list for PBXNativeTarget "Segmented" */ = { 296 | isa = XCConfigurationList; 297 | buildConfigurations = ( 298 | 96EC3F3E1CFC2C8E00BD8BA7 /* Debug */, 299 | 96EC3F3F1CFC2C8E00BD8BA7 /* Release */, 300 | ); 301 | defaultConfigurationIsVisible = 0; 302 | defaultConfigurationName = Release; 303 | }; 304 | /* End XCConfigurationList section */ 305 | }; 306 | rootObject = 96EC3F231CFC2C8E00BD8BA7 /* Project object */; 307 | } 308 | -------------------------------------------------------------------------------- /Segmented.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /Segmented.xcodeproj/project.xcworkspace/xcuserdata/dwipp.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented.xcodeproj/project.xcworkspace/xcuserdata/dwipp.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /Segmented.xcodeproj/xcuserdata/dwipp.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /Segmented.xcodeproj/xcuserdata/dwipp.xcuserdatad/xcschemes/Segmented.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Segmented.xcodeproj/xcuserdata/dwipp.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | Segmented.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 96EC3F2A1CFC2C8E00BD8BA7 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /Segmented/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // Segmented 4 | // 5 | // Created by Dwi Permana Putra on 5/30/16. 6 | // Copyright © 2016 Dwi Permana Putra. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | 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 inactive 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 | -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_gray.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodnormal_disable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodnormal_disable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodnormal_disable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_gray.imageset/iconmoodnormal_disable@3x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_white.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodnormal_enable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodnormal_enable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodnormal_enable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/flat_white.imageset/iconmoodnormal_enable@3x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_gray.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodhappy_disable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodhappy_disable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodhappy_disable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_gray.imageset/iconmoodhappy_disable@3x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_white.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodhappy_enable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodhappy_enable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodhappy_enable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/happy_white.imageset/iconmoodhappy_enable@3x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_gray.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodsad_disable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodsad_disable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodsad_disable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_gray.imageset/iconmoodsad_disable@3x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_white.imageset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "universal", 5 | "filename" : "iconmoodsad_enable.png", 6 | "scale" : "1x" 7 | }, 8 | { 9 | "idiom" : "universal", 10 | "filename" : "iconmoodsad_enable@2x.png", 11 | "scale" : "2x" 12 | }, 13 | { 14 | "idiom" : "universal", 15 | "filename" : "iconmoodsad_enable@3x.png", 16 | "scale" : "3x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable@2x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable@2x.png -------------------------------------------------------------------------------- /Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable@3x.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPSegmentedControl/a01ea37a6b2f22e4563c19e63b627b7e29e8eb6f/Segmented/Assets.xcassets/sad_white.imageset/iconmoodsad_enable@3x.png -------------------------------------------------------------------------------- /Segmented/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 | -------------------------------------------------------------------------------- /Segmented/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 | -------------------------------------------------------------------------------- /Segmented/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 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | UIInterfaceOrientationLandscapeLeft 37 | UIInterfaceOrientationLandscapeRight 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /Segmented/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // Segmented 4 | // 5 | // Created by Dwi Permana Putra on 5/30/16. 6 | // Copyright © 2016 Dwi Permana Putra. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | 13 | // var segmentedControl: DPSegmentedControl! 14 | override func viewDidLoad() { 15 | super.viewDidLoad() 16 | 17 | let screen = UIScreen.mainScreen().bounds 18 | 19 | let segmentedControl = DPSegmentedControl.init( 20 | FrameWithIcon: CGRectMake(8, 50, screen.width - 16, 44), 21 | items: ["Happy", "Normal", "Sad"], 22 | icons: [UIImage(named: "happy_gray")!, UIImage(named: "flat_gray")!, UIImage(named: "sad_gray")!], 23 | selectedIcons: [UIImage(named: "happy_white")!, UIImage(named: "flat_white")!, UIImage(named: "sad_white")!], 24 | backgroundColor: UIColor(red: 230/255, green: 230/255, blue: 230/255, alpha: 1), 25 | thumbColor: UIColor.init(hex: "#54C3EF"), 26 | textColor: UIColor(hex: "#808080"), 27 | selectedTextColor: UIColor(hex: "#FFFFFF"), 28 | orientation: ComponentOrientation.LeftRight) 29 | 30 | segmentedControl.selectedIndex = 1 31 | 32 | segmentedControl.addTarget(self, action: #selector(self.action(_:)), forControlEvents: .ValueChanged) 33 | self.view.addSubview(segmentedControl) 34 | 35 | } 36 | 37 | override func viewWillAppear(animated: Bool) { 38 | 39 | } 40 | 41 | func action(sender: DPSegmentedControl){ 42 | print("sender: \(sender.selectedIndex)") 43 | } 44 | 45 | override func didReceiveMemoryWarning() { 46 | super.didReceiveMemoryWarning() 47 | // Dispose of any resources that can be recreated. 48 | } 49 | 50 | 51 | } 52 | 53 | extension UIColor { 54 | convenience init(hex:String) { 55 | let hexString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()) 56 | let scanner = NSScanner(string: hexString) 57 | 58 | if (hexString.hasPrefix("#")) { 59 | scanner.scanLocation = 1 60 | } 61 | 62 | var color:UInt32 = 0 63 | scanner.scanHexInt(&color) 64 | 65 | let mask = 0x000000FF 66 | let r = Int(color >> 16) & mask 67 | let g = Int(color >> 8) & mask 68 | let b = Int(color) & mask 69 | 70 | let red = CGFloat(r) / 255.0 71 | let green = CGFloat(g) / 255.0 72 | let blue = CGFloat(b) / 255.0 73 | 74 | self.init(red:red, green:green, blue:blue, alpha:1) 75 | } 76 | } 77 | 78 | --------------------------------------------------------------------------------