designatednerd / dnscastrosegmentedcontrol Goto Github PK
View Code? Open in Web Editor NEWA segmented control based on the one in the Castro Podcast app's settings page.
License: MIT License
A segmented control based on the one in the Castro Podcast app's settings page.
License: MIT License
Hello,
This isn't really a bug, but more of a feature request.
I noticed that you hardcoded the radius value. Why not just expose the divider a public property? This way we could personalize the radius ourselves:
CGFloat cornerRadius = (CGRectGetHeight(self.frame) / publicRadiusVariable);
The higher the value - the more square corners will get. I'd probably submit a PR, but I'm more of a Swift person and just afraid to mess things up :)
It's possible for the control to be deallocated without registering for KVO. When this happens, this code will throw an exception:
- (void)dealloc
{
[self removeObserver:self forKeyPath:[self boundsKeyPath]];
}
Here's the ugly solution as suggested by NSHipster:
- (void) dealloc {
@try {
[self removeObserver:self forKeyPath:[self boundsKeyPath]];
} @catch(NSException * __unused exception){}
}
The current implementation does this:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
// some stuff…
[self setSelectedSegmentIndex:roundedSection animated:YES];
}
I believe most users will consider it unexpected if an app's state changes while they're still dragging their finger. Normally, it's safe to drag controls around on the screen, and nothing will take effect until the finger is lifted. For example, in Settings, a user can drag the Airplane Mode switch right and left, and Airplane Mode won't enable unless they lift their finger while the switch is enabled.
Instead, I believe this behavior should be in touchesEnded:
, and touchesCancelled:
should revert selectionView
to its original state.
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
[self touchesEndedOrCancelled];
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
[super touchesMoved:touches withEvent:event];
[self touchesEndedOrCancelled];
}
These methods both call touchesMoved:
instead of their appropriate super
method.
If this is intentional, can we document the reason?
From layoutSubviews
:
if (!self.choices) {
NSAssert(@"NO", @"Cannot setup with no choices set!");
}
However, @"NO"
evaluates to YES
, so the assert is never thrown.
I suggest we assert the actual condition:
NSAssert(self.choices, @"Cannot setup with no choices set!");
This would allow us to remove the conditional.
This will require some refactoring since right now the selection chiclet is at a z-level above the images/labels.
Options:
After discussing #2 with @jacobvanorder, we determined that the main issue he was trying to address would be solved by automatically calculating the intrinsic width of the control based on length of strings, which is not done right now.
The link to castro goes to castrofm.com and I think it should go to castro.fm.
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.