VLCProgressView.m 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*****************************************************************************
  2. * VLCProgressView.m
  3. * VLC for iOS
  4. *****************************************************************************
  5. * Copyright (c) 2014 VideoLAN. All rights reserved.
  6. * $Id$
  7. *
  8. * Authors: Carola Nitz <nitz.carola # googlemail.com>
  9. *
  10. * Refer to the COPYING file of the official project for license.
  11. *****************************************************************************/
  12. #import "VLCProgressView.h"
  13. @implementation VLCProgressView
  14. - (instancetype)init
  15. {
  16. self = [super init];
  17. if (self) {
  18. [self setup];
  19. }
  20. return self;
  21. }
  22. - (void)setup
  23. {
  24. self.progressBar = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleBar];
  25. self.progressLabel = [[UILabel alloc] init];
  26. self.progressLabel.textColor = [UIColor whiteColor];
  27. self.progressLabel.font = [UIFont systemFontOfSize:11.];
  28. self.progressLabel.translatesAutoresizingMaskIntoConstraints = NO;
  29. self.progressBar.translatesAutoresizingMaskIntoConstraints = NO;
  30. [self addSubview:_progressBar];
  31. [self addSubview:_progressLabel];
  32. [self addConstraint:[NSLayoutConstraint constraintWithItem:self attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:_progressLabel attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
  33. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[_progressBar(200)]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressBar)]];
  34. [self addConstraint:[NSLayoutConstraint constraintWithItem:self.progressBar attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0f constant:0.0f]];
  35. [self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-[_progressBar]-[_progressLabel]-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_progressBar, _progressLabel)]];
  36. }
  37. - (void)updateTime:(NSString *)time
  38. {
  39. [self.progressLabel setText:[NSString stringWithFormat:NSLocalizedString(@"REMAINING_TIME", nil), time]];
  40. CGSize size = [self.progressLabel.text sizeWithFont:self.progressLabel.font];
  41. [self.progressLabel setFrame:CGRectMake(self.progressLabel.frame.origin.x, self.progressLabel.frame.origin.y, size.width, size.height)];
  42. }
  43. @end