chore: import upstream snapshot with attribution
This commit is contained in:
+13
@@ -0,0 +1,13 @@
|
||||
//
|
||||
// TLChatFontViewController.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLViewController.h"
|
||||
|
||||
@interface TLChatFontViewController : TLViewController
|
||||
|
||||
@end
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
//
|
||||
// TLChatFontViewController.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/21.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLChatFontViewController.h"
|
||||
#import "TLChatMessageDisplayView.h"
|
||||
#import "TLChatFontSettingView.h"
|
||||
#import "TLUser+ChatModel.h"
|
||||
#import "NSFileManager+TLChat.h"
|
||||
#import "TLUserHelper.h"
|
||||
|
||||
@interface TLChatFontViewController ()
|
||||
|
||||
@property (nonatomic, strong) TLChatMessageDisplayView *messageDisplayView;
|
||||
|
||||
@property (nonatomic, strong) TLChatFontSettingView *chatFontSettingView;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation TLChatFontViewController
|
||||
|
||||
- (void)viewDidLoad
|
||||
{
|
||||
[super viewDidLoad];
|
||||
[self.navigationItem setTitle:LOCSTR(@"字体大小")];
|
||||
|
||||
[self.view addSubview:self.messageDisplayView];
|
||||
[self.view addSubview:self.chatFontSettingView];
|
||||
[self p_addMasonry];
|
||||
|
||||
__weak typeof(self) weakSelf = self;
|
||||
[self.chatFontSettingView setFontSizeChangeTo:^(CGFloat size) {
|
||||
[[NSUserDefaults standardUserDefaults] setDouble:size forKey:@"CHAT_FONT_SIZE"];
|
||||
weakSelf.messageDisplayView.data = [weakSelf p_messageDisplayViewData];
|
||||
[weakSelf.messageDisplayView reloadData];
|
||||
}];
|
||||
CGFloat size = [[NSUserDefaults standardUserDefaults] doubleForKey:@"CHAT_FONT_SIZE"];
|
||||
[self.chatFontSettingView setCurFontSize:size];
|
||||
self.messageDisplayView.data = [self p_messageDisplayViewData];
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.messageDisplayView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.top.and.left.and.right.mas_equalTo(self.view);
|
||||
make.bottom.mas_equalTo(self.chatFontSettingView.mas_top);
|
||||
}];
|
||||
|
||||
[self.chatFontSettingView mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.and.right.and.bottom.mas_equalTo(self.view);
|
||||
make.height.mas_equalTo(self.chatFontSettingView.mas_width).multipliedBy(0.4);
|
||||
}];
|
||||
}
|
||||
|
||||
- (NSMutableArray *)p_messageDisplayViewData
|
||||
{
|
||||
TLTextMessage *message = [[TLTextMessage alloc] init];
|
||||
message.fromUser = [TLUserHelper sharedHelper].user;
|
||||
message.ownerTyper = TLMessageOwnerTypeSelf;
|
||||
message.text = @"预览字体大小";
|
||||
|
||||
TLUser *user = [[TLUser alloc] init];
|
||||
user.avatarPath = @"AppIcon";
|
||||
NSString *path = [NSFileManager pathUserAvatar:@"AppIcon"];
|
||||
if (![[NSFileManager defaultManager] isExecutableFileAtPath:path]) {
|
||||
NSString *iconPath = [[[[NSBundle mainBundle] infoDictionary] valueForKeyPath:@"CFBundleIcons.CFBundlePrimaryIcon.CFBundleIconFiles"] lastObject];
|
||||
UIImage *image = [UIImage imageNamed:iconPath];
|
||||
NSData *data = (UIImagePNGRepresentation(image) ? UIImagePNGRepresentation(image) :UIImageJPEGRepresentation(image, 1));
|
||||
[[NSFileManager defaultManager] createFileAtPath:path contents:data attributes:nil];
|
||||
}
|
||||
|
||||
|
||||
TLTextMessage *message1 = [[TLTextMessage alloc] init];
|
||||
message1.fromUser = user;
|
||||
message1.ownerTyper = TLMessageOwnerTypeFriend;
|
||||
message1.text = @"拖动下面的滑块,可设置字体大小";
|
||||
TLTextMessage *message2 = [[TLTextMessage alloc] init];
|
||||
message2.fromUser = user;
|
||||
message2.ownerTyper = TLMessageOwnerTypeFriend;
|
||||
message2.text = @"设置后,会改变聊天页面的字体大小。后续将支持更改菜单、朋友圈的字体修改。";
|
||||
|
||||
NSMutableArray *data = [[NSMutableArray alloc] initWithObjects:message, message1, message2, nil];
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (TLChatMessageDisplayView *)messageDisplayView
|
||||
{
|
||||
if (_messageDisplayView == nil) {
|
||||
_messageDisplayView = [[TLChatMessageDisplayView alloc] init];
|
||||
[_messageDisplayView setDisablePullToRefresh:YES];
|
||||
[_messageDisplayView setDisableLongPressMenu:YES];
|
||||
}
|
||||
return _messageDisplayView;
|
||||
}
|
||||
|
||||
- (TLChatFontSettingView *)chatFontSettingView
|
||||
{
|
||||
if (_chatFontSettingView == nil) {
|
||||
_chatFontSettingView = [[TLChatFontSettingView alloc] init];
|
||||
}
|
||||
return _chatFontSettingView;
|
||||
}
|
||||
|
||||
@end
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
//
|
||||
// TLChatFontSettingView.h
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/22.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import <UIKit/UIKit.h>
|
||||
|
||||
#define MIN_FONT_SIZE 15.0f
|
||||
#define STANDARD_FONT_SZIE 16.0f
|
||||
#define MAX_FONT_SZIE 20.0f
|
||||
|
||||
@interface TLChatFontSettingView : UIView
|
||||
|
||||
@property (nonatomic, assign) CGFloat curFontSize;
|
||||
|
||||
@property (nonatomic, copy) void (^fontSizeChangeTo)(CGFloat size);
|
||||
|
||||
|
||||
@end
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
//
|
||||
// TLChatFontSettingView.m
|
||||
// TLChat
|
||||
//
|
||||
// Created by 李伯坤 on 16/3/22.
|
||||
// Copyright © 2016年 李伯坤. All rights reserved.
|
||||
//
|
||||
|
||||
#import "TLChatFontSettingView.h"
|
||||
|
||||
@interface TLChatFontSettingView ()
|
||||
|
||||
@property (nonatomic, strong) UILabel *miniFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UILabel *maxFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UILabel *standardFontLabel;
|
||||
|
||||
@property (nonatomic, strong) UISlider *slider;
|
||||
|
||||
@end
|
||||
|
||||
@implementation TLChatFontSettingView
|
||||
|
||||
- (id)initWithFrame:(CGRect)frame
|
||||
{
|
||||
if (self = [super initWithFrame:frame]) {
|
||||
[self setBackgroundColor:[UIColor whiteColor]];
|
||||
[self addSubview:self.miniFontLabel];
|
||||
[self addSubview:self.maxFontLabel];
|
||||
[self addSubview:self.standardFontLabel];
|
||||
[self addSubview:self.slider];
|
||||
[self p_addMasonry];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)setCurFontSize:(CGFloat)curFontSize
|
||||
{
|
||||
_curFontSize = curFontSize;
|
||||
[self.slider setValue:curFontSize];
|
||||
}
|
||||
|
||||
#pragma mark - Event Response -
|
||||
- (void)sliderValueChanged:(UISlider *)sender
|
||||
{
|
||||
NSInteger value = (NSInteger)sender.value;
|
||||
value = ((sender.value - value) > 0.5 ? value + 1 : value);
|
||||
if (value == (NSInteger)_curFontSize) {
|
||||
return;
|
||||
}
|
||||
_curFontSize = value;
|
||||
if (self.fontSizeChangeTo) {
|
||||
self.fontSizeChangeTo(value);
|
||||
}
|
||||
}
|
||||
|
||||
#pragma mark - Private Methods -
|
||||
- (void)p_addMasonry
|
||||
{
|
||||
[self.miniFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.left.mas_equalTo(self.slider.mas_left);
|
||||
make.bottom.mas_equalTo(self.slider.mas_top).mas_offset(-6);
|
||||
}];
|
||||
|
||||
[self.maxFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.right.mas_equalTo(self.slider.mas_right);
|
||||
make.bottom.mas_equalTo(self.miniFontLabel);
|
||||
}];
|
||||
|
||||
[self.standardFontLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.bottom.mas_equalTo(self.miniFontLabel);
|
||||
make.left.mas_equalTo(self.miniFontLabel.mas_right).mas_equalTo(40);
|
||||
}];
|
||||
|
||||
[self.slider mas_makeConstraints:^(MASConstraintMaker *make) {
|
||||
make.centerX.mas_equalTo(self);
|
||||
make.bottom.mas_equalTo(self.mas_bottom).mas_offset(-35);
|
||||
make.width.mas_equalTo(self).multipliedBy(0.8);
|
||||
make.height.mas_equalTo(40);
|
||||
}];
|
||||
}
|
||||
|
||||
#pragma mark - Getter -
|
||||
- (UILabel *)miniFontLabel
|
||||
{
|
||||
if (_miniFontLabel == nil) {
|
||||
_miniFontLabel = [[UILabel alloc] init];
|
||||
[_miniFontLabel setFont:[UIFont systemFontOfSize:MIN_FONT_SIZE]];
|
||||
[_miniFontLabel setText:@"A"];
|
||||
}
|
||||
return _miniFontLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)maxFontLabel
|
||||
{
|
||||
if (_maxFontLabel == nil) {
|
||||
_maxFontLabel = [[UILabel alloc] init];
|
||||
[_maxFontLabel setFont:[UIFont systemFontOfSize:MAX_FONT_SZIE]];
|
||||
[_maxFontLabel setText:@"A"];
|
||||
}
|
||||
return _maxFontLabel;
|
||||
}
|
||||
|
||||
- (UILabel *)standardFontLabel
|
||||
{
|
||||
if (_standardFontLabel == nil) {
|
||||
_standardFontLabel = [[UILabel alloc] init];
|
||||
[_standardFontLabel setFont:[UIFont systemFontOfSize:STANDARD_FONT_SZIE]];
|
||||
[_standardFontLabel setText:@"标准"];
|
||||
}
|
||||
return _standardFontLabel;
|
||||
}
|
||||
|
||||
- (UISlider *)slider
|
||||
{
|
||||
if (_slider == nil) {
|
||||
_slider = [[UISlider alloc] init];
|
||||
[_slider setMinimumValue:MIN_FONT_SIZE];
|
||||
[_slider setMaximumValue:MAX_FONT_SZIE];
|
||||
[_slider addTarget:self action:@selector(sliderValueChanged:) forControlEvents:UIControlEventValueChanged];
|
||||
}
|
||||
return _slider;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in New Issue
Block a user