1
0
mirror of https://github.com/danog/Telegram.git synced 2024-12-11 17:09:46 +01:00
Telegram/Telegraph/TGCheckCollectionItemView.m

90 lines
2.3 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 "TGCheckCollectionItemView.h"
#import "TGImageUtils.h"
#import "TGFont.h"
@interface TGCheckCollectionItemView ()
{
UIImageView *_checkView;
UILabel *_label;
}
@end
@implementation TGCheckCollectionItemView
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self != nil)
{
self.separatorInset = 44.0f;
_label = [[UILabel alloc] init];
2015-10-01 18:19:52 +02:00
_label.textAlignment = NSTextAlignmentLeft;
2014-07-10 16:11:09 +02:00
_label.textColor = [UIColor blackColor];
_label.backgroundColor = [UIColor clearColor];
_label.font = TGSystemFontOfSize(17);
[self addSubview:_label];
_checkView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"ModernMenuCheck.png"]];
[self addSubview:_checkView];
}
return self;
}
- (void)setTitle:(NSString *)title
{
_label.text = title;
[self setNeedsLayout];
}
- (void)setIsChecked:(bool)isChecked
{
_checkView.hidden = !isChecked;
}
- (void)setDrawsFullSeparator:(bool)drawsFullSeparator
{
_drawsFullSeparator = drawsFullSeparator;
2015-10-01 18:19:52 +02:00
self.separatorInset = drawsFullSeparator ? 0.0f : (_alignToRight ? 15.0f : 44.0f);
2014-07-10 16:11:09 +02:00
}
- (void)layoutSubviews
{
[super layoutSubviews];
CGRect bounds = self.bounds;
if (_drawsFullSeparator)
{
CGFloat separatorHeight = TGIsRetina() ? 0.5f : 1.0f;
2015-10-01 18:19:52 +02:00
_topStripeView.frame = CGRectMake(self.separatorInset, 0.0f, self.frame.size.width - self.separatorInset, separatorHeight * 2.0f);
2014-07-10 16:11:09 +02:00
}
2015-10-01 18:19:52 +02:00
if (_alignToRight)
{
_label.frame = CGRectMake(15.0f, CGFloor((bounds.size.height - 26) / 2), bounds.size.width - 44.0f - 16.0f, 26);
CGSize checkSize = _checkView.frame.size;
_checkView.frame = CGRectMake(bounds.size.width - 15.0f - checkSize.width, 16.0f, checkSize.width, checkSize.height);
}
else
{
_label.frame = CGRectMake(44.0f, CGFloor((bounds.size.height - 26) / 2), bounds.size.width - 44.0f - 16.0f, 26);
CGSize checkSize = _checkView.frame.size;
_checkView.frame = CGRectMake(15.0f, 16.0f, checkSize.width, checkSize.height);
}
2014-07-10 16:11:09 +02:00
}
@end