session-ios/Session/Conversations/ConversationScrollButton.m

100 lines
2.6 KiB
Mathematica
Raw Normal View History

//
2019-02-06 06:36:03 +01:00
// Copyright (c) 2019 Open Whisper Systems. All rights reserved.
//
#import "ConversationScrollButton.h"
#import "UIColor+OWS.h"
#import "UIFont+OWS.h"
#import "UIView+OWS.h"
2020-11-11 07:45:50 +01:00
#import <SignalUtilitiesKit/Theme.h>
2019-12-11 00:25:53 +01:00
#import "Session-Swift.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];
if (!self) {
return self;
}
self.iconText = iconText;
[self createContents];
return self;
}
2017-11-22 15:39:11 +01:00
+ (CGFloat)circleSize
{
return ScaleFromIPhone5To7Plus(35.f, 40.f);
}
2017-11-22 15:39:11 +01:00
+ (CGFloat)buttonSize
{
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;
UIView *circleView = [UIView new];
self.circleView = circleView;
circleView.userInteractionEnabled = NO;
2017-11-22 15:39:11 +01:00
circleView.layer.cornerRadius = circleSize * 0.5f;
2021-01-29 01:46:32 +01:00
circleView.layer.borderColor = [LKColors.text colorWithAlphaComponent:LKValues.lowOpacity].CGColor;
2019-12-11 00:25:53 +01:00
circleView.layer.borderWidth = LKValues.composeViewTextFieldBorderThickness;
2017-11-22 15:39:11 +01:00
[circleView autoSetDimension:ALDimensionWidth toSize:circleSize];
[circleView autoSetDimension:ALDimensionHeight toSize:circleSize];
[self addSubview:circleView];
[self addSubview:iconLabel];
[circleView autoCenterInSuperview];
[iconLabel autoCenterInSuperview];
[self updateColors];
}
- (void)setHasUnreadMessages:(BOOL)hasUnreadMessages
{
_hasUnreadMessages = hasUnreadMessages;
[self updateColors];
}
- (void)updateColors
{
2019-12-11 00:25:53 +01:00
UIColor *foregroundColor = LKColors.text;
UIColor *backgroundColor = LKColors.composeViewBackground;
2018-08-07 23:51:09 +02:00
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:@{
2019-12-11 00:25:53 +01:00
NSFontAttributeName : [UIFont ows_fontAwesomeFont:circleSize * 0.75f],
2018-08-07 23:51:09 +02:00
NSForegroundColorAttributeName : foregroundColor,
NSBaselineOffsetAttributeName : @(-0.5f),
}];
}
@end
NS_ASSUME_NONNULL_END