123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- // _____ _
- // |_ _| |_ _ _ ___ ___ _ __ __ _
- // | | | ' \| '_/ -_) -_) ' \/ _` |_
- // |_| |_||_|_| \___\___|_|_|_\__,_(_)
- //
- // Threema iOS Client
- // Copyright (c) 2014-2020 Threema GmbH
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU Affero General Public License, version 3,
- // as published by the Free Software Foundation.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU Affero General Public License for more details.
- //
- // You should have received a copy of the GNU Affero General Public License
- // along with this program. If not, see <https://www.gnu.org/licenses/>.
- #import "SlaveScrollView.h"
- #import "BallotMatrixLabelView.h"
- #import "BallotResultMatrixCell.h"
- @interface SlaveScrollView ()
- @property ScrollViewContent *contentView;
- @property CGFloat maxX;
- @property CGFloat maxY;
- @end
- @implementation SlaveScrollView
- - (instancetype)initWithFrame:(CGRect)frame
- {
- self = [super initWithFrame:frame];
- if (self) {
- _horizontalScrollingEnabled = YES;
- self.clipsToBounds = YES;
- self.alwaysBounceVertical = NO;
- self.alwaysBounceHorizontal = NO;
- self.showsVerticalScrollIndicator = NO;
- self.showsHorizontalScrollIndicator = NO;
- }
-
- return self;
- }
- - (void)setContent:(ScrollViewContent *)contentView {
- if (_contentView != contentView) {
- [_contentView removeFromSuperview];
- }
-
- _contentView = contentView;
- [self addSubview:_contentView];
- [self updateContentSize];
- }
- - (void)setFrame:(CGRect)frame {
- [super setFrame:frame];
-
- [self updateContentSize];
- }
- - (void)updateContentSize {
- [_contentView adaptToWidth: self.frame.size.width];
- [self setContentSize: _contentView.frame.size];
- _maxX = roundf(_contentView.bounds.size.width - self.bounds.size.width);
- _maxY = roundf(_contentView.bounds.size.height - self.bounds.size.height);
- }
- - (CGPoint)setPosition:(CGPoint)position {
- CGFloat x = fmaxf(0.0, position.x);
- x = fminf(x, _maxX);
-
- if (_maxX < 0.0 || _horizontalScrollingEnabled == NO) {
- x = 0.0;
- }
-
- CGFloat y = fmaxf(0.0, position.y);
- y = fminf(y, _maxY);
- if (_maxY < 0.0) {
- y = 0.0;
- }
- CGPoint resultingPosition = CGPointMake(x, y);
- self.contentOffset = resultingPosition;
-
- return resultingPosition;
- }
- - (CGPoint)position {
- return self.contentOffset;
- }
- - (void)setColor:(UIColor *)color forRowAt:(NSInteger)index {
- NSArray *subviews = [self.contentView subviews];
-
- if (index < [subviews count]) {
- UIView *view = [subviews objectAtIndex:index];
- view.backgroundColor = color;
- }
- }
- - (void)setTextColor:(UIColor *)color forRowAt:(NSInteger)index {
- NSArray *subviews = [self.contentView subviews];
- if (index < [subviews count]) {
- UIView *view = [subviews objectAtIndex:index];
- if ([view isKindOfClass:[BallotMatrixLabelView class]] && ([Colors getTheme] == ColorThemeLight || [Colors getTheme] == ColorThemeLightWork)) {
- BallotMatrixLabelView *b = (BallotMatrixLabelView *)view;
- [b setTextColor:[Colors fontInverted]];
- } else {
- NSArray *subsub = [view subviews];
- [subsub enumerateObjectsUsingBlock:^(id v, NSUInteger idx, BOOL * _Nonnull stop) {
- if ([v isKindOfClass:[BallotResultMatrixCell class]]) {
- BallotResultMatrixCell *cell = (BallotResultMatrixCell *)v;
- [cell setColorForChoice:[Colors fontInverted]];
- }
- }];
- }
- }
- }
- @end
|