1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-02 09:27:55 +01:00
Telegram/Telegraph/TGCommentCollectionItemView.m

118 lines
2.8 KiB
Mathematica
Raw Normal View History

2014-07-10 16:11:09 +02:00
/*
* This is the source code of Telegram for iOS v. 1.1
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
* Copyright Peter Iakovlev, 2013.
*/
#import "TGCommentCollectionItemView.h"
#import "TGFont.h"
@interface TGCommentCollectionItemView ()
{
UILabel *_label;
2015-10-01 18:19:52 +02:00
UIActivityIndicatorView *_activityIndicator;
2014-07-10 16:11:09 +02:00
}
@end
@implementation TGCommentCollectionItemView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self)
{
_label = [[UILabel alloc] init];
_label.backgroundColor = [UIColor clearColor];
_label.numberOfLines = 0;
[self addSubview:_label];
2015-10-01 18:19:52 +02:00
[_label addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapGesture:)]];
2014-07-10 16:11:09 +02:00
}
return self;
}
2015-10-01 18:19:52 +02:00
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
2014-07-10 16:11:09 +02:00
{
2015-10-01 18:19:52 +02:00
if (CGRectContainsPoint(_label.frame, point))
return _label;
return [super hitTest:point withEvent:event];
}
- (void)tapGesture:(UITapGestureRecognizer *)recognizer
{
if (recognizer.state == UIGestureRecognizerStateRecognized)
{
if (_action)
_action();
}
}
- (void)setTextColor:(UIColor *)textColor
{
_label.textColor = textColor;
}
- (void)setLabelAlpha:(CGFloat)labelAlpha
{
_labelAlpha = labelAlpha;
_label.alpha = labelAlpha;
_activityIndicator.alpha = labelAlpha;
}
- (void)setAttributedText:(NSAttributedString *)text
{
_label.attributedText = text;
[self setNeedsLayout];
}
- (void)setTopInset:(CGFloat)topInset
{
_topInset = topInset;
[self setNeedsLayout];
}
- (void)setCalculatedSize:(CGSize)calculatedSize
{
_calculatedSize = calculatedSize;
[self setNeedsLayout];
}
- (void)setShowProgress:(bool)showProgress
{
_showProgress = showProgress;
if (_showProgress && _activityIndicator == nil)
{
_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
_activityIndicator.hidden = true;
_activityIndicator.alpha = _label.alpha;
[self addSubview:_activityIndicator];
[self setNeedsLayout];
}
if (_showProgress)
{
_activityIndicator.hidden = false;
[_activityIndicator startAnimating];
}
else
{
_activityIndicator.hidden = true;
[_activityIndicator stopAnimating];
}
2014-07-10 16:11:09 +02:00
}
- (void)layoutSubviews
{
[super layoutSubviews];
2015-10-01 18:19:52 +02:00
_label.frame = CGRectMake(15.0f, 7.0f + _topInset, self.bounds.size.width - 30.0f, _calculatedSize.height - 7.0f - 7.0f);
_activityIndicator.frame = CGRectMake(15.0f, 14.0f, _activityIndicator.frame.size.width, _activityIndicator.frame.size.height);
2014-07-10 16:11:09 +02:00
}
@end