Dynamic resizing of TGPControls
This commit is contained in:
parent
c5659d0423
commit
53433b4bc2
|
|
@ -16,7 +16,7 @@ Pod::Spec.new do |s|
|
|||
#
|
||||
|
||||
s.name = "TGPControls"
|
||||
s.version = "0.0.1"
|
||||
s.version = "0.0.2"
|
||||
s.summary = "Custom Awesome iOS Controls."
|
||||
|
||||
s.description = <<-DESC
|
||||
|
|
@ -68,7 +68,7 @@ Pod::Spec.new do |s|
|
|||
# Supports git, hg, bzr, svn and HTTP.
|
||||
#
|
||||
|
||||
s.source = { :git => "https://github.com/arquebuse/TGPControls.git", :tag => "0.0.1" }
|
||||
s.source = { :git => "https://github.com/arquebuse/TGPControls.git", :tag => "v0.0.2" }
|
||||
|
||||
|
||||
# ――― Source Code ―――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――― #
|
||||
|
|
@ -80,7 +80,8 @@ Pod::Spec.new do |s|
|
|||
#
|
||||
|
||||
s.source_files = "TGPControls", "TGPControls/**/*.{h,m}"
|
||||
# s.exclude_files = "TGPControls/**/*.{h,m}"
|
||||
s.exclude_files = "TGPControlsDemo7/*", "TGPControlsDemo/*"
|
||||
|
||||
|
||||
s.public_header_files = "TGPControls/**/*.{h}"
|
||||
|
||||
|
|
|
|||
|
|
@ -50,6 +50,7 @@
|
|||
DC101D6B1A75749600ECCF80 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
DC101D7A1A75756300ECCF80 /* TGPControls_License.txt */ = {isa = PBXFileReference; lastKnownFileType = text; path = TGPControls_License.txt; sourceTree = "<group>"; };
|
||||
DC101D7B1A75756300ECCF80 /* TGPControls.podspec */ = {isa = PBXFileReference; lastKnownFileType = text; path = TGPControls.podspec; sourceTree = "<group>"; };
|
||||
DC28A54D1A947704003C9405 /* TGPControlsTicksProtocol.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TGPControlsTicksProtocol.h; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
|
@ -76,6 +77,7 @@
|
|||
children = (
|
||||
DC0468E51A7596690084DE3E /* TGPCamelLabels.h */,
|
||||
DC0468E61A7596690084DE3E /* TGPCamelLabels.m */,
|
||||
DC28A54D1A947704003C9405 /* TGPControlsTicksProtocol.h */,
|
||||
DC0468E81A7596930084DE3E /* TGPDiscreteSlider.h */,
|
||||
DC0468E91A7596930084DE3E /* TGPDiscreteSlider.m */,
|
||||
DC0468DF1A75962E0084DE3E /* TGPCamelLabels7.h */,
|
||||
|
|
|
|||
|
|
@ -29,8 +29,9 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TGPControlsTicksProtocol.h"
|
||||
|
||||
@interface TGPCamelLabels7 : UIControl
|
||||
@interface TGPCamelLabels7 : UIControl <TGPControlsTicksProtocol>
|
||||
|
||||
@property (nonatomic) NSUInteger tickCount; // Only used if [labels count] < 1
|
||||
@property (nonatomic) CGFloat ticksDistance;
|
||||
|
|
|
|||
|
|
@ -118,6 +118,14 @@
|
|||
return self;
|
||||
}
|
||||
|
||||
// When bounds change, recalculate layout
|
||||
- (void)setBounds:(CGRect)bounds
|
||||
{
|
||||
[super setBounds:bounds];
|
||||
[self layoutTrack];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
// clickthrough
|
||||
-(BOOL)pointInside:(CGPoint)point withEvent:(UIEvent *)event {
|
||||
for (UIView *view in self.subviews) {
|
||||
|
|
@ -127,7 +135,7 @@
|
|||
return NO;
|
||||
}
|
||||
|
||||
#pragma mark TGPCamelSlider
|
||||
#pragma mark TGPCamelLabels
|
||||
|
||||
- (void)initProperties {
|
||||
_ticksDistance = 44.0;
|
||||
|
|
@ -282,4 +290,10 @@
|
|||
[aView setAlpha:alpha];
|
||||
}
|
||||
|
||||
#pragma mark - TGPControlsTicksProtocol
|
||||
|
||||
-(void)tgpTicksDistanceChanged:(CGFloat)ticksDistance sender:(id)sender
|
||||
{
|
||||
self.ticksDistance = ticksDistance;
|
||||
}
|
||||
@end
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
// @file: TGPControlsTicksProtocol.h
|
||||
// @project: TGPControls
|
||||
//
|
||||
// @history: Created November 27, 2014 (Thanksgiving Day)
|
||||
// @author: Xavier Schott
|
||||
// mailto://xschott@gmail.com
|
||||
// http://thegothicparty.com
|
||||
// tel://+18089383634
|
||||
//
|
||||
// @license: http://opensource.org/licenses/MIT
|
||||
// Copyright (c) 2014, Xavier Schott
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in
|
||||
// all copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
// THE SOFTWARE.
|
||||
|
||||
@protocol TGPControlsTicksProtocol<NSObject>
|
||||
@required
|
||||
-(void)tgpTicksDistanceChanged:(CGFloat)ticksDistance sender:(id)sender;
|
||||
@end
|
||||
|
|
@ -29,6 +29,7 @@
|
|||
// THE SOFTWARE.
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
#import "TGPControlsTicksProtocol.h"
|
||||
|
||||
@interface TGPDiscreteSlider7 :
|
||||
|
||||
|
|
@ -61,6 +62,8 @@ typedef NS_ENUM(int, ComponentStyle) {
|
|||
@property (nonatomic) CGFloat thumbShadowRadius;
|
||||
@property (nonatomic) CGSize thumbShadowOffset;
|
||||
|
||||
@property (nonatomic, weak) NSObject<TGPControlsTicksProtocol> * ticksListener;
|
||||
|
||||
// AKA: UISlider value (as CGFloat for compatibility with UISlider API, but expected to contain integers)
|
||||
@property (nonatomic) CGFloat minimumValue;
|
||||
@property (nonatomic) CGFloat value;
|
||||
|
|
|
|||
|
|
@ -128,6 +128,14 @@ static CGSize iosThumbShadowOffset = (CGSize){0, 3};
|
|||
return _intValue; // calculated property, with a float-to-int adapter
|
||||
}
|
||||
|
||||
// When bounds change, recalculate layout
|
||||
- (void)setBounds:(CGRect)bounds
|
||||
{
|
||||
[super setBounds:bounds];
|
||||
[self layoutTrack];
|
||||
[self setNeedsDisplay];
|
||||
}
|
||||
|
||||
#pragma mark UIControl
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder {
|
||||
|
|
@ -351,8 +359,10 @@ static CGSize iosThumbShadowOffset = (CGSize){0, 3};
|
|||
const CGFloat originX = (thumbWidth / 2) + (CGFloat)(trackLength * ratio);
|
||||
[self.ticksAbscisses addObject: [NSValue valueWithCGPoint:CGPointMake(originX, trackY)]];
|
||||
}
|
||||
|
||||
[self layoutThumb];
|
||||
|
||||
// If we have a TGPDiscreteSliderTicksListener (such as TGPCamelLabels), broadcast new spacing
|
||||
[self.ticksListener tgpTicksDistanceChanged:self.ticksDistance sender:self];
|
||||
}
|
||||
|
||||
- (void)layoutThumb {
|
||||
|
|
|
|||
Loading…
Reference in New Issue