2013-06-21 17:48:06 -07:00
|
|
|
//
|
|
|
|
// IASKPSSliderSpecifierViewCell.m
|
|
|
|
// http://www.inappsettingskit.com
|
|
|
|
//
|
|
|
|
// Copyright (c) 2009-2010:
|
|
|
|
// Luc Vandal, Edovia Inc., http://www.edovia.com
|
|
|
|
// Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz,
|
|
|
|
// as the original authors of this code. You can give credit in a blog post, a tweet or on
|
|
|
|
// a info page of your app. Also, the original authors appreciate letting them know if you use this code.
|
|
|
|
//
|
|
|
|
// This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
|
|
|
|
//
|
|
|
|
|
|
|
|
#import "IASKPSSliderSpecifierViewCell.h"
|
|
|
|
#import "IASKSlider.h"
|
|
|
|
#import "IASKSettingsReader.h"
|
|
|
|
|
|
|
|
@implementation IASKPSSliderSpecifierViewCell
|
|
|
|
|
|
|
|
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
|
|
|
|
{
|
|
|
|
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
|
|
|
|
if (self) {
|
|
|
|
// Setting only frame data that will not be overwritten by layoutSubviews
|
|
|
|
// Slider
|
2013-10-08 16:00:55 -07:00
|
|
|
_slider = [[IASKSlider alloc] initWithFrame:CGRectMake(0, 0, 0, 23)];
|
2013-06-21 17:48:06 -07:00
|
|
|
_slider.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin |
|
|
|
|
UIViewAutoresizingFlexibleWidth;
|
|
|
|
_slider.continuous = NO;
|
|
|
|
[self.contentView addSubview:_slider];
|
|
|
|
|
|
|
|
// MinImage
|
2013-10-08 16:00:55 -07:00
|
|
|
_minImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 21, 21)];
|
2013-06-21 17:48:06 -07:00
|
|
|
_minImage.autoresizingMask = UIViewAutoresizingFlexibleRightMargin |
|
|
|
|
UIViewAutoresizingFlexibleBottomMargin;
|
|
|
|
[self.contentView addSubview:_minImage];
|
|
|
|
|
|
|
|
// MaxImage
|
2013-10-08 16:00:55 -07:00
|
|
|
_maxImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 21, 21)];
|
2013-06-21 17:48:06 -07:00
|
|
|
_maxImage.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |
|
|
|
|
UIViewAutoresizingFlexibleBottomMargin;
|
|
|
|
[self.contentView addSubview:_maxImage];
|
|
|
|
|
|
|
|
self.selectionStyle = UITableViewCellSelectionStyleNone;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)layoutSubviews {
|
|
|
|
[super layoutSubviews];
|
2015-03-03 15:56:32 -05:00
|
|
|
|
|
|
|
UIEdgeInsets padding = (UIEdgeInsets) { 0, kIASKPaddingLeft, 0, kIASKPaddingRight };
|
|
|
|
if ([self respondsToSelector:@selector(layoutMargins)]) {
|
|
|
|
padding = [self layoutMargins];
|
|
|
|
}
|
2013-06-21 17:48:06 -07:00
|
|
|
CGRect sliderBounds = _slider.bounds;
|
|
|
|
CGPoint sliderCenter = _slider.center;
|
2013-10-08 16:00:55 -07:00
|
|
|
const CGFloat superViewWidth = _slider.superview.frame.size.width;
|
2013-06-21 17:48:06 -07:00
|
|
|
|
2015-03-03 15:56:32 -05:00
|
|
|
sliderBounds.size.width = superViewWidth - (padding.left + padding.right);
|
|
|
|
sliderCenter.x = padding.left + sliderBounds.size.width / 2;
|
2013-06-21 17:48:06 -07:00
|
|
|
sliderCenter.y = self.contentView.center.y;
|
|
|
|
_minImage.hidden = YES;
|
|
|
|
_maxImage.hidden = YES;
|
|
|
|
|
|
|
|
// Check if there are min and max images. If so, change the layout accordingly.
|
|
|
|
if (_minImage.image) {
|
|
|
|
// Min image
|
|
|
|
_minImage.hidden = NO;
|
2015-03-03 15:56:32 -05:00
|
|
|
sliderBounds.size.width -= _minImage.frame.size.width + kIASKSliderImageGap;
|
|
|
|
sliderCenter.x += (_minImage.frame.size.width + kIASKSliderImageGap) / 2;
|
|
|
|
_minImage.center = CGPointMake(_minImage.frame.size.width / 2 + padding.left,
|
2013-06-21 17:48:06 -07:00
|
|
|
self.contentView.center.y);
|
|
|
|
}
|
|
|
|
if (_maxImage.image) {
|
|
|
|
// Max image
|
|
|
|
_maxImage.hidden = NO;
|
2015-03-03 15:56:32 -05:00
|
|
|
sliderBounds.size.width -= kIASKSliderImageGap + _maxImage.frame.size.width;
|
|
|
|
sliderCenter.x -= (kIASKSliderImageGap + _maxImage.frame.size.width) / 2;
|
|
|
|
_maxImage.center = CGPointMake(superViewWidth - padding.right - _maxImage.frame.size.width /2, self.contentView.center.y );
|
2013-06-21 17:48:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
_slider.bounds = sliderBounds;
|
|
|
|
_slider.center = sliderCenter;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)prepareForReuse {
|
2015-09-16 16:53:07 -07:00
|
|
|
[super prepareForReuse];
|
2013-06-21 17:48:06 -07:00
|
|
|
_minImage.image = nil;
|
|
|
|
_maxImage.image = nil;
|
|
|
|
}
|
|
|
|
@end
|