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

78 lines
2.1 KiB
Mathematica
Raw Normal View History

2016-02-25 01:03:51 +01:00
#import "TGMenuSheetButtonItemView.h"
#import "TGModernButton.h"
#import "TGFont.h"
const CGFloat TGMenuSheetButtonItemViewHeight = 57.0f;
@interface TGMenuSheetButtonItemView ()
{
TGModernButton *_button;
}
@property (nonatomic, copy) void(^action)(void);
@end
@implementation TGMenuSheetButtonItemView
- (instancetype)initWithTitle:(NSString *)title type:(TGMenuSheetButtonType)type action:(void (^)(void))action
{
self = [super initWithType:(type == TGMenuSheetButtonTypeCancel) ? TGMenuSheetItemTypeFooter : TGMenuSheetItemTypeDefault];
if (self != nil)
{
self.action = action;
_button = [[TGModernButton alloc] init];
_button.exclusiveTouch = true;
_button.highlightBackgroundColor = UIColorRGB(0xebebeb);
_button.titleLabel.font = (type == TGMenuSheetButtonTypeCancel || type == TGMenuSheetButtonTypeSend) ? TGMediumSystemFontOfSize(20) : TGSystemFontOfSize(20);
[_button setTitleColor:(type == TGMenuSheetButtonTypeDestructive) ? TGDestructiveAccentColor() : TGAccentColor()];
[_button setTitle:title forState:UIControlStateNormal];
[_button addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:_button];
__weak TGMenuSheetButtonItemView *weakSelf = self;
_button.highlitedChanged = ^(bool highlighted)
{
__strong TGMenuSheetButtonItemView *strongSelf = weakSelf;
if (strongSelf != nil && strongSelf.highlightUpdateBlock != nil)
strongSelf.highlightUpdateBlock(highlighted);
};
}
return self;
}
- (void)buttonPressed
{
if (self.action != nil)
self.action();
}
- (NSString *)title
{
return [_button titleForState:UIControlStateNormal];
}
- (void)setTitle:(NSString *)title
{
[_button setTitle:title forState:UIControlStateNormal];
}
- (CGFloat)preferredHeightForWidth:(CGFloat)__unused width screenHeight:(CGFloat)__unused screenHeight
{
return TGMenuSheetButtonItemViewHeight;
}
- (bool)requiresDivider
{
return true;
}
- (void)layoutSubviews
{
_button.frame = self.bounds;
}
@end