Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class OthersFormViewController : XLFormViewController {
row.cellConfigAtConfigure["slider.maximumValue"] = 100
row.cellConfigAtConfigure["slider.minimumValue"] = 10
row.cellConfigAtConfigure["steps"] = 4
row.cellConfigAtConfigure["showValue"] = true;
section.addFormRow(row)


Expand Down
13 changes: 12 additions & 1 deletion XLForm/XL/Cell/XLFormSliderCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ @interface XLFormSliderCell ()
@property (nonatomic) UISlider * slider;
@property (nonatomic) UILabel * textLabel;
@property NSUInteger steps;
@property UILabel * valueLabel;
@property Boolean showValue; // if true then display the numeric value to 2 d.p.

@end

Expand All @@ -41,13 +43,16 @@ @implementation XLFormSliderCell
- (void)configure
{
self.steps = 0;
self.showValue = false;
[self.slider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
[self.contentView addSubview:self.slider];
[self.contentView addSubview:self.textLabel];
self.valueLabel = [UILabel autolayoutView];
[self.contentView addSubview:self.valueLabel];
self.selectionStyle = UITableViewCellSelectionStyleNone;
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.textLabel attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:10]];
[self.contentView addConstraint:[NSLayoutConstraint constraintWithItem:self.slider attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.contentView attribute:NSLayoutAttributeTop multiplier:1 constant:44]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[textLabel]-15-|" options:0 metrics:0 views:@{@"textLabel": self.textLabel}]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[textLabel]-15-[valueLabel]-15-|" options:0 metrics:0 views:@{@"textLabel": self.textLabel,@"valueLabel": self.valueLabel}]];
[self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-15-[slider]-15-|" options:0 metrics:0 views:@{@"slider": self.slider}]];

[self valueChanged:nil];
Expand All @@ -57,6 +62,9 @@ -(void)update {

[super update];
self.textLabel.text = self.rowDescriptor.title;
if (self.showValue) {
self.valueLabel.text = [NSString stringWithFormat:@"%.2f", self.slider.value];
}
self.slider.value = [self.rowDescriptor.value floatValue];
self.slider.enabled = !self.rowDescriptor.isDisabled;
[self valueChanged:nil];
Expand All @@ -66,6 +74,9 @@ -(void)valueChanged:(UISlider*)_slider {
if(self.steps != 0) {
self.slider.value = roundf((self.slider.value-self.slider.minimumValue)/(self.slider.maximumValue-self.slider.minimumValue)*self.steps)*(self.slider.maximumValue-self.slider.minimumValue)/self.steps + self.slider.minimumValue;
}
if (self.showValue) {
self.valueLabel.text = [NSString stringWithFormat:@"%.2f", self.slider.value];
}
self.rowDescriptor.value = @(self.slider.value);
}

Expand Down