gontovnik / dgrunkeeperswitch Goto Github PK
View Code? Open in Web Editor NEWRunkeeper design switch control
License: MIT License
Runkeeper design switch control
License: MIT License
Adding storyboard makes it easier to add more UI and design to the projects
In the example app, modify the ViewController.swift
's runkeeperSwitch2
to be laid out using autolayout programmatically, like:
let runkeeperSwitch2 = DGRunkeeperSwitch()
runkeeperSwitch2.leftTitle = "Weekly"
runkeeperSwitch2.rightTitle = "Monthly"
runkeeperSwitch2.backgroundColor = UIColor(red: 239.0/255.0, green: 95.0/255.0, blue: 49.0/255.0, alpha: 1.0)
runkeeperSwitch2.selectedBackgroundColor = .whiteColor()
runkeeperSwitch2.titleColor = .whiteColor()
runkeeperSwitch2.selectedTitleColor = UIColor(red: 239.0/255.0, green: 95.0/255.0, blue: 49.0/255.0, alpha: 1.0)
runkeeperSwitch2.titleFont = UIFont(name: "HelveticaNeue-Medium", size: 13.0)
//runkeeperSwitch2.frame = CGRect(x: 50.0, y: 20.0, width: view.bounds.width - 100.0, height: 30.0)
//runkeeperSwitch2.autoresizingMask = [.FlexibleWidth]
runkeeperSwitch2.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(runkeeperSwitch2)
view.addConstraints(NSLayoutConstraint.constraintsWithVisualFormat("H:|-20-[switch]-20-|", options: .DirectionLeadingToTrailing, metrics: nil, views: ["switch":runkeeperSwitch2]))
view.addConstraint(NSLayoutConstraint(item: runkeeperSwitch2, attribute: .Top, relatedBy: .Equal, toItem: view, attribute: .Top, multiplier: 1.0, constant: 10))
runkeeperSwitch2.addConstraint(NSLayoutConstraint(item: runkeeperSwitch2, attribute: .Height, relatedBy: .Equal, toItem: nil, attribute: .NotAnAttribute, multiplier: 1.0, constant: 30.0))
And this is what happens in the iOS simulator:
Do you have any idea why the border radius is not working using the above code?
I am running this on lates xcode 7 beta 6.
Any setting of the background color in IB is ignored. This is because and IB-View is instantiated with initWithCoder:
which sets the background color. After that finishInit
is called which overwrites the setting.
Can you make it Carthage compatible?
It's not that hard, just add a Framework build scheme and make it shared.
hi
how can three switch in one DGRunkeeperSwitch ??
runkeeperSwitch.addTarget(self, action: #selector(ViewController.switchValueDidChange(sender:)), for: .touchUpInside)
target-action mechanism will not work because of added UITapGestureRecognizer to control
It fails with error *** Terminating app due to uncaught exception ‘CALayerInvalidGeometry’, reason: ‘CALayer position contains NaN: [nan 15.5]’
As a workaround - create with empty strings ("")
Would be great if Carthage was supported. We don't use Cocoapods at my company.
Hey! Is it possible to make the value change when I use swipeGestures? I can't do it for some reason.
Regards!
I'm trying to find out how to change the the segment programatically?
Hello! Thanks for the great framework! How can I monitor changes to selected index? I did not find a delegate or call block for this, thank you.
A way to handle longer text. Ability to enable multi-line and choose line a lineBreakMode.
Hello
I have this error with Merge branch 'pr/23' update
error: IB Designables: Failed to update auto layout status: The agent raised a "CALayerInvalidGeometry" exception: CALayer position contains NaN: [nan 15.5]
and
error: IB Designables: Failed to render instance of DGRunkeeperSwitch: The agent threw an exception.
I put the switch into storyboard as navigation title as a view with custom class (DGRunkeeperSwitch)
the position of the view is
x 200
y 7
w 200
h 31
everything else is defaults for the view. without constraints
in code the switch is set with 2 elements
but everything seems to be working as before
ps: the latest version of xcode suggests these changes
// Gestures
- tapGesture = UITapGestureRecognizer(target: self, action: "tapped:")
+ tapGesture = UITapGestureRecognizer(target: self, action: #selector(DGRunkeeperSwitch.tapped(_:)))
- panGesture = UIPanGestureRecognizer(target: self, action: "pan:")
+ panGesture = UIPanGestureRecognizer(target: self, action: #selector(DGRunkeeperSwitch.pan(_:)))
I saw that you added swift support but when we try to add this in our pod file it gives an error.
pod 'DGRunkeeperSwitch', '~> 1.1.4'
did you mean to put version 1.1.3?
with swift 4 does not work
Hi! I'm trying to integrate your project with obj-c code, so i'm using option 'use_frameworks!' for pod install.
When i import this module, none of classes are visible. That is because classes are not public.
Could you please provide public access level for main classes?
P.S. i know that there is already objective-c implementation, but i want to be sure that i'd have your last updates just in time.
Thanks
Could you please add a property to change the border radius?
On iOS 11 there are increased warnings related to KVO and the KVO code in DGRunkeeperSwitch.swift doesn't work. I get this assertion failure
[MyTests.TableViewCellTest testOutlets] : failed: caught "NSUnknownKeyException", "[<DGRunkeeperSwitch.DGRunkeeperSwitch 0x7feec8220100> addObserver:<DGRunkeeperSwitch.DGRunkeeperSwitch 0x7feec8220100> forKeyPath:@"selectedBackgroundView.frame" options:1 context:0x0] was sent to an object that is not KVC-compliant for the "selectedBackgroundView" property."
I fixed this problem as follows:
In finishInit I changed to this
selectedBackgroundView.addObserver(self, forKeyPath: "frame", options: .new, context: nil)
In observeValue forKeyPath I changed to this
override open func observeValue(forKeyPath keyPath: String?, of object: Any?, change: [NSKeyValueChangeKey : Any]?, context: UnsafeMutableRawPointer?) {
if let view = object as? UIView {
if keyPath == "frame" && view == selectedBackgroundView {
titleMaskView.frame = selectedBackgroundView.frame
}
}
}
and
deinit {
selectedBackgroundView.removeObserver(self, forKeyPath: "frame")
}
Couple of recommendations:
Cheers.
Really like what I see, but I would be interested in using DGRunkeeperSwitch with more than two options, more like a Segmented Control. Would be a great enhancement in my opinion!
Best,
Josef
In order for the control to have a flexible width and work with autolayout. You need to add
runkeeperSwitch2.autoresizingMask = [.flexibleWidth]
This is documented in the example project but not in the README. I can't the only one that missed this first time around.
Happy to make a PR updating the README
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.