Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Background Border Width/Color Added #127

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Example/BetterSegmentedControl.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
607FACEA1AFB9204008FA782 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
607FACEB1AFB9204008FA782 /* Tests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tests.swift; sourceTree = "<group>"; };
61D9FAAAFFAE7994D65963C2 /* Pods_BetterSegmentedControl_Example.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_BetterSegmentedControl_Example.framework; sourceTree = BUILT_PRODUCTS_DIR; };
82FBC36B5CC2D9017CEACA5B /* BetterSegmentedControl.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = BetterSegmentedControl.podspec; path = ../BetterSegmentedControl.podspec; sourceTree = "<group>"; };
82FBC36B5CC2D9017CEACA5B /* BetterSegmentedControl.podspec */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text; name = BetterSegmentedControl.podspec; path = ../BetterSegmentedControl.podspec; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.ruby; };
BA399992832E9047B3FF6F8B /* Pods-BetterSegmentedControl_Tests.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BetterSegmentedControl_Tests.release.xcconfig"; path = "Pods/Target Support Files/Pods-BetterSegmentedControl_Tests/Pods-BetterSegmentedControl_Tests.release.xcconfig"; sourceTree = "<group>"; };
E35EF8EE3A68B8AA955DE5DE /* Pods-BetterSegmentedControl_Example.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BetterSegmentedControl_Example.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BetterSegmentedControl_Example/Pods-BetterSegmentedControl_Example.debug.xcconfig"; sourceTree = "<group>"; };
F6F6B8A01C1E078308A9EB93 /* Pods-BetterSegmentedControl_Tests.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-BetterSegmentedControl_Tests.debug.xcconfig"; path = "Pods/Target Support Files/Pods-BetterSegmentedControl_Tests/Pods-BetterSegmentedControl_Tests.debug.xcconfig"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -219,6 +219,7 @@
TargetAttributes = {
607FACCF1AFB9204008FA782 = {
CreatedOnToolsVersion = 6.3.1;
DevelopmentTeam = 2BLC39WP62;
LastSwiftMigration = 1020;
};
607FACE41AFB9204008FA782 = {
Expand Down Expand Up @@ -513,6 +514,7 @@
baseConfigurationReference = E35EF8EE3A68B8AA955DE5DE /* Pods-BetterSegmentedControl_Example.debug.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 2BLC39WP62;
INFOPLIST_FILE = BetterSegmentedControl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand All @@ -526,6 +528,7 @@
baseConfigurationReference = 12CB0D1475C52C17775132BF /* Pods-BetterSegmentedControl_Example.release.xcconfig */;
buildSettings = {
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
DEVELOPMENT_TEAM = 2BLC39WP62;
INFOPLIST_FILE = BetterSegmentedControl/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
MODULE_NAME = ExampleApp;
Expand Down
22 changes: 22 additions & 0 deletions Example/BetterSegmentedControl/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ class ViewController: UIViewController {
height: 32.0),
titles: ["First", "Second", "Third"])
view.addSubview(appleStyledControl)

// Control 7: Added as a line button
let borderSegmentedControl = BetterSegmentedControl(
frame: CGRect(x: 0.0, y: 332.0, width: view.bounds.width , height: 50.0),
segments: LabelSegment.segments(withTitles: ["Artists", "Albums"],
normalFont: UIFont(name: "HelveticaNeue", size: 16.0)!,
normalTextColor: .gray,
selectedFont: UIFont(name: "HelveticaNeue", size: 16.0)!,
selectedTextColor: UIColor(red: 0.97, green: 0.00, blue: 0.24, alpha: 1.00)),
index: 1,
options: [.backgroundColor(UIColor.white),
.backgroundBorderColor(UIColor.green),
.backgroundBorderWidth(1.0),
.indicatorViewBackgroundColor(UIColor.white),
.indicatorViewBorderWidth(1.0),
.indicatorViewBorderColor(UIColor.red),
.indicatorViewInset(0.0),
.cornerRadius(0.0),
.animationSpringDamping(1.0),
.panningDisabled(true)])

view.addSubview(borderSegmentedControl)
}

// MARK: - Action handlers
Expand Down
2 changes: 1 addition & 1 deletion Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,4 @@ SPEC CHECKSUMS:

PODFILE CHECKSUM: a84635a977f3d0e6850e7888935f489adb8fd939

COCOAPODS: 1.8.4
COCOAPODS: 1.9.0.beta.2
28 changes: 28 additions & 0 deletions Pod/Classes/BetterSegmentedControl.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ import UIKit
panningDisabled = value
case let .backgroundColor(value):
backgroundColor = value
case let .backgroundBorderColor(value):
backgroundBorderColor = value
case let .backgroundBorderWidth(value):
backgroundBorderWidth = value
case let .cornerRadius(value):
cornerRadius = value
case let .animationDuration(value):
Expand Down Expand Up @@ -150,6 +154,30 @@ import UIKit
indicatorView.layer.borderColor = newValue?.cgColor
}
}

/// The background view's border color.
@IBInspectable public var backgroundBorderColor: UIColor? {
get {
guard let color = normalSegmentsView.layer.borderColor else {
return nil
}
return UIColor(cgColor: color)
}
set {
normalSegmentsView.layer.borderColor = newValue?.cgColor
}
}

/// The background view's border width.
@IBInspectable public var backgroundBorderWidth: CGFloat {
get {
return normalSegmentsView.layer.borderWidth
}
set {
normalSegmentsView.layer.borderWidth = newValue
}
}

/// The duration of the animation of an index change. Defaults to `0.3`.
@IBInspectable public var animationDuration: TimeInterval = 0.3
/// The spring damping ratio of the animation of an index change. Defaults to `0.75`. Set to `1.0` for a no bounce effect.
Expand Down
2 changes: 2 additions & 0 deletions Pod/Classes/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public enum BetterSegmentedControlOption {

/* Other */
case backgroundColor(UIColor)
case backgroundBorderColor(UIColor)
case backgroundBorderWidth(CGFloat)
case cornerRadius(CGFloat)
}