Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Custom Slider Cell with Value Label #430

Open
WA-Will opened this issue Nov 30, 2015 · 0 comments
Open

Custom Slider Cell with Value Label #430

WA-Will opened this issue Nov 30, 2015 · 0 comments

Comments

@WA-Will
Copy link

WA-Will commented Nov 30, 2015

I'm working to modify the existing slider cell to include a value label. I've shown my modifications here. The slider is in the correct position, but the label showing the value isn't showing. Can you point me in the right direction here?

screenshot

@interface FXFormSliderCell ()

@property (nonatomic, strong) UISlider *slider;

@end


@implementation FXFormSliderCell

- (void)setUp
{
    self.slider = [[UISlider alloc] init];
    self.field.value = [[UILabel alloc] init];

    [self.slider addTarget:self action:@selector(valueChanged) forControlEvents:UIControlEventValueChanged];
    [self.contentView addSubview:self.slider];
    [self.contentView addSubview:self.field.value];

    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)layoutSubviews
{
    [super layoutSubviews];

    CGRect labelFrame = self.textLabel.frame;
    labelFrame.origin.y = FXFormFieldPaddingTop;
    labelFrame.size.width = MIN(MAX([self.textLabel sizeThatFits:CGSizeZero].width, FXFormFieldMinLabelWidth), FXFormFieldMaxLabelWidth);
    self.textLabel.frame = labelFrame;

    CGRect valueFrame = self.valueLabel.frame;
    valueFrame.origin.x = self.contentView.bounds.size.width - FXFormFieldPaddingLeft;
    valueFrame.origin.y = FXFormFieldPaddingTop;
    valueFrame.size.width = MIN(MAX([self.textLabel sizeThatFits:CGSizeZero].width, FXFormFieldMinLabelWidth), FXFormFieldMaxLabelWidth);
    self.valueLabel.frame = valueFrame;

    CGRect sliderFrame = self.slider.frame;
    sliderFrame.origin.x = FXFormFieldPaddingLeft;
    sliderFrame.origin.y = self.textLabel.frame.size.height + FXFormFieldPaddingTop;
    sliderFrame.size.width = self.contentView.bounds.size.width - sliderFrame.origin.x - FXFormFieldPaddingRight;
    sliderFrame.size.height = self.textLabel.frame.size.height + FXFormFieldPaddingTop + FXFormFieldPaddingBottom;
    self.slider.frame = sliderFrame;

}

- (void)update
{
    self.textLabel.text = self.field.title;
    self.textLabel.accessibilityValue = self.textLabel.text;
    self.slider.value = [self.field.value doubleValue];
}

- (void)valueChanged
{
    self.field.value = @(self.slider.value);
    self.valueLabel.text = [NSString stringWithFormat:@"%f", self.slider.value];

    if (self.field.action) self.field.action(self);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant