2017-11-21 22:23:42 +01:00
|
|
|
//
|
2018-08-07 23:51:09 +02:00
|
|
|
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
2017-11-21 22:23:42 +01:00
|
|
|
//
|
|
|
|
|
|
|
|
#import "ConversationScrollButton.h"
|
|
|
|
#import "UIColor+OWS.h"
|
|
|
|
#import "UIFont+OWS.h"
|
|
|
|
#import "UIView+OWS.h"
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
|
|
|
@interface ConversationScrollButton ()
|
|
|
|
|
|
|
|
@property (nonatomic) NSString *iconText;
|
|
|
|
@property (nonatomic) UILabel *iconLabel;
|
|
|
|
@property (nonatomic) UIView *circleView;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
#pragma mark -
|
|
|
|
|
|
|
|
@implementation ConversationScrollButton
|
|
|
|
|
|
|
|
- (nullable instancetype)initWithIconText:(NSString *)iconText
|
|
|
|
{
|
2017-11-22 15:39:11 +01:00
|
|
|
self = [super initWithFrame:CGRectZero];
|
2017-11-21 22:23:42 +01:00
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
self.iconText = iconText;
|
|
|
|
|
|
|
|
[self createContents];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:39:11 +01:00
|
|
|
+ (CGFloat)circleSize
|
2017-11-21 22:23:42 +01:00
|
|
|
{
|
|
|
|
return ScaleFromIPhone5To7Plus(35.f, 40.f);
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:39:11 +01:00
|
|
|
+ (CGFloat)buttonSize
|
2017-11-21 22:23:42 +01:00
|
|
|
{
|
|
|
|
return self.circleSize + 2 * 15.f;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)createContents
|
|
|
|
{
|
|
|
|
UILabel *iconLabel = [UILabel new];
|
|
|
|
self.iconLabel = iconLabel;
|
|
|
|
iconLabel.userInteractionEnabled = NO;
|
|
|
|
|
2017-11-22 15:39:11 +01:00
|
|
|
const CGFloat circleSize = self.class.circleSize;
|
2017-11-21 22:23:42 +01:00
|
|
|
UIView *circleView = [UIView new];
|
|
|
|
self.circleView = circleView;
|
|
|
|
circleView.userInteractionEnabled = NO;
|
2017-11-22 15:39:11 +01:00
|
|
|
circleView.layer.cornerRadius = circleSize * 0.5f;
|
2017-11-21 22:23:42 +01:00
|
|
|
circleView.layer.shadowColor = [UIColor colorWithWhite:0.5f alpha:1.f].CGColor;
|
|
|
|
circleView.layer.shadowOffset = CGSizeMake(+1.f, +2.f);
|
|
|
|
circleView.layer.shadowRadius = 1.5f;
|
|
|
|
circleView.layer.shadowOpacity = 0.35f;
|
2017-11-22 15:39:11 +01:00
|
|
|
[circleView autoSetDimension:ALDimensionWidth toSize:circleSize];
|
|
|
|
[circleView autoSetDimension:ALDimensionHeight toSize:circleSize];
|
2017-11-21 22:23:42 +01:00
|
|
|
|
|
|
|
[self addSubview:circleView];
|
|
|
|
[self addSubview:iconLabel];
|
|
|
|
[circleView autoCenterInSuperview];
|
|
|
|
[iconLabel autoCenterInSuperview];
|
|
|
|
|
|
|
|
[self updateColors];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setHasUnreadMessages:(BOOL)hasUnreadMessages
|
|
|
|
{
|
|
|
|
_hasUnreadMessages = hasUnreadMessages;
|
|
|
|
|
|
|
|
[self updateColors];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)updateColors
|
|
|
|
{
|
2018-08-07 23:51:09 +02:00
|
|
|
UIColor *foregroundColor;
|
|
|
|
UIColor *backgroundColor;
|
|
|
|
if (self.hasUnreadMessages) {
|
|
|
|
foregroundColor = UIColor.whiteColor;
|
|
|
|
backgroundColor = UIColor.ows_materialBlueColor;
|
|
|
|
} else if (Theme.isDarkThemeEnabled) {
|
|
|
|
foregroundColor = UIColor.ows_materialBlueColor;
|
|
|
|
backgroundColor = [UIColor colorWithWhite:0.25f alpha:1.f];
|
|
|
|
} else {
|
|
|
|
foregroundColor = UIColor.ows_materialBlueColor;
|
|
|
|
backgroundColor = [UIColor colorWithWhite:0.95f alpha:1.f];
|
|
|
|
}
|
|
|
|
|
2017-11-22 15:39:11 +01:00
|
|
|
const CGFloat circleSize = self.class.circleSize;
|
2018-08-07 23:51:09 +02:00
|
|
|
self.circleView.backgroundColor = backgroundColor;
|
|
|
|
self.iconLabel.attributedText =
|
|
|
|
[[NSAttributedString alloc] initWithString:self.iconText
|
|
|
|
attributes:@{
|
|
|
|
NSFontAttributeName : [UIFont ows_fontAwesomeFont:circleSize * 0.8f],
|
|
|
|
NSForegroundColorAttributeName : foregroundColor,
|
|
|
|
NSBaselineOffsetAttributeName : @(-0.5f),
|
|
|
|
}];
|
2017-11-21 22:23:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|