Commit 5171e35acb8594172b53ad37c1dfe61a5f349071

Authored by zhangxiaowen
1 parent 59224536

no message

Showing 26 changed files with 723 additions and 1 deletions
CNLiveSettingModule.podspec
@@ -82,6 +82,13 @@ TODO: 网家家-设置模块. @@ -82,6 +82,13 @@ TODO: 网家家-设置模块.
82 82
83 end 83 end
84 84
  85 + # 设置字体大小
  86 + s.subspec 'FontSIze' do |ss|
  87 + ss.source_files = 'CNLiveSettingModule/Classes/FontSIze/*.{h,m}'
  88 + ss.dependency 'CNLiveBaseKit'
  89 +
  90 + end
  91 +
85 s.resource_bundles = { 92 s.resource_bundles = {
86 'CNLiveSettingModule' => ['CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets'] 93 'CNLiveSettingModule' => ['CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets']
87 } 94 }
CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_logo.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "font_size_logo@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "font_size_logo@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_logo.imageset/font_size_logo@2x.png 0 → 100644

5.98 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_logo.imageset/font_size_logo@3x.png 0 → 100644

14.4 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_me.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "font_size_message_me@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "font_size_message_me@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_me.imageset/font_size_message_me@2x.png 0 → 100644

1.38 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_me.imageset/font_size_message_me@3x.png 0 → 100644

3.1 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_other.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "font_size_message_other@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "font_size_message_other@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_other.imageset/font_size_message_other@2x.png 0 → 100644

1.25 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_message_other.imageset/font_size_message_other@3x.png 0 → 100644

2.82 KB

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_slider.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "font_size_slider@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "font_size_slider@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_slider.imageset/font_size_slider@2x.png 0 → 100644

506 Bytes

CNLiveSettingModule/Assets/CNLiveSettingModule.xcassets/font_size_slider.imageset/font_size_slider@3x.png 0 → 100644

1.21 KB

CNLiveSettingModule/Classes/Controller/CNLiveSettingController.m
@@ -21,6 +21,7 @@ @@ -21,6 +21,7 @@
21 #import "CNLivePrivacyController.h"//隐私 21 #import "CNLivePrivacyController.h"//隐私
22 #import "CNLiveCancellationController.h"//注销 22 #import "CNLiveCancellationController.h"//注销
23 #import "CNLiveAboutUsController.h"//关于我们 23 #import "CNLiveAboutUsController.h"//关于我们
  24 +#import "CNLiveFontSettingController.h"//设置字体大小
24 25
25 @interface CNLiveSettingController () 26 @interface CNLiveSettingController ()
26 <UITableViewDelegate, UITableViewDataSource, CNLiveSettingNavigationBarDelegate> 27 <UITableViewDelegate, UITableViewDataSource, CNLiveSettingNavigationBarDelegate>
@@ -196,7 +197,8 @@ static const NSInteger timeValue = 1.5; @@ -196,7 +197,8 @@ static const NSInteger timeValue = 1.5;
196 [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementUnderstand]; 197 [CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementUnderstand];
197 } 198 }
198 else if(indexPath.row == 4){ // 字体大小 199 else if(indexPath.row == 4){ // 字体大小
199 - 200 + CNLiveFontSettingController *vc = [[CNLiveFontSettingController alloc]init];
  201 + [self.navigationController pushViewController:vc animated:YES];
200 } 202 }
201 else if(indexPath.row == 5){ // 隐私 203 else if(indexPath.row == 5){ // 隐私
202 CNLivePrivacyController *vc = [[CNLivePrivacyController alloc]init]; 204 CNLivePrivacyController *vc = [[CNLivePrivacyController alloc]init];
@@ -379,4 +381,5 @@ static const NSInteger timeValue = 1.5; @@ -379,4 +381,5 @@ static const NSInteger timeValue = 1.5;
379 } 381 }
380 } 382 }
381 383
  384 +
382 @end 385 @end
CNLiveSettingModule/Classes/FontSIze/CNLiveFontSettingController.h 0 → 100644
  1 +//
  2 +// CNLiveFontSettingController.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/8/21.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface CNLiveFontSettingController : UIViewController
  12 +
  13 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveFontSettingController.m 0 → 100644
  1 +//
  2 +// CNLiveFontSettingController.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/8/21.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveFontSettingController.h"
  10 +
  11 +#import "QMUIKit.h"
  12 +#import "CNLiveBaseKit.h"
  13 +
  14 +#import "CNLiveSettingNavigationBar.h"
  15 +#import "CNLiveMessageFrame.h"
  16 +#import "CNLiveMessageModel.h"
  17 +#import "CNLiveMessageCell.h"
  18 +
  19 +@interface CNLiveFontSettingController ()<UIGestureRecognizerDelegate, UITableViewDelegate, UITableViewDataSource, CNLiveSettingNavigationBarDelegate>
  20 +@property (nonatomic, strong) CNLiveSettingNavigationBar *navigationBar;
  21 +@property (nonatomic, strong) UITableView *tableView;
  22 +@property (nonatomic, strong) NSMutableArray *data;
  23 +
  24 +@property (nonatomic, strong) QMUISlider *slider;
  25 +@property (nonatomic, strong) UITapGestureRecognizer *tapGesture;
  26 +
  27 +@end
  28 +
  29 +@implementation CNLiveFontSettingController{
  30 + NSInteger tempCoefficient;
  31 +}
  32 +- (void)setupDataSource{
  33 + CNLiveMessageFrame * frame1 = [[CNLiveMessageFrame alloc]init];
  34 + CNLiveMessageModel * message1 = [[CNLiveMessageModel alloc]init];
  35 + message1.content = @"预览字体大小";
  36 + message1.fromMe = @"1";
  37 + frame1.message = message1;
  38 + [self.data addObject:frame1];
  39 +
  40 + CNLiveMessageFrame * frame2 = [[CNLiveMessageFrame alloc]init];
  41 + CNLiveMessageModel * message2 = [[CNLiveMessageModel alloc]init];
  42 + message2.content = @"拖拽下面的滑块,可设置字体大小";
  43 + message2.fromMe = @"0";
  44 + frame2.message = message2;
  45 +
  46 + [self.data addObject:frame2];
  47 +
  48 + CNLiveMessageFrame * frame3 = [[CNLiveMessageFrame alloc]init];
  49 + CNLiveMessageModel * message3 = [[CNLiveMessageModel alloc]init];
  50 + message3.content = [NSString stringWithFormat:@"设置后,可改变聊天、菜单中的字体大小。如果在使用过程中存在问题或意见,可反馈给%@",@"网家家"];
  51 + message3.fromMe = @"0";
  52 + frame3.message = message3;
  53 +
  54 + [self.data addObject:frame3];
  55 +}
  56 +
  57 +- (void)viewWillAppear:(BOOL)animated{
  58 + [super viewWillAppear:animated];
  59 + self.navigationController.navigationBarHidden = YES;
  60 +
  61 + if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  62 + self.navigationController.interactivePopGestureRecognizer.enabled = NO;
  63 + }
  64 +}
  65 +
  66 +- (void)viewWillDisappear:(BOOL)animated{
  67 + [super viewWillDisappear:animated];
  68 + if ([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
  69 + self.navigationController.interactivePopGestureRecognizer.enabled = YES;
  70 + }
  71 +}
  72 +
  73 +- (void)viewDidLoad {
  74 + [super viewDidLoad];
  75 + tempCoefficient = [[NSUserDefaults standardUserDefaults] integerForKey:@"CNSizeFontCoefficient"];
  76 +
  77 + self.view.backgroundColor = [UIColor colorWithRed:242/255.0 green:242/255.0 blue:242/255.0 alpha:1.0];
  78 +
  79 + [self setupDataSource];
  80 + [self setupView];
  81 + [self addSliderView];
  82 +
  83 +}
  84 +
  85 +- (void)setupView{
  86 + [self.view addSubview:self.navigationBar];
  87 + [self.view addSubview:self.tableView];
  88 +}
  89 +
  90 +- (void)addSliderView{
  91 + UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.frame.size.height-130, self.view.frame.size.width, 130)];
  92 + bottomView.backgroundColor = [UIColor whiteColor];
  93 + [self.view addSubview:bottomView];
  94 +
  95 + self.slider = [[QMUISlider alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-70, 30)];
  96 + _slider.center = CGPointMake(bottomView.frame.size.width/2, bottomView.frame.size.height-50);
  97 + _slider.minimumValue = 1;
  98 + _slider.maximumValue = 5;
  99 + _slider.minimumTrackTintColor = [UIColor clearColor];
  100 + _slider.maximumTrackTintColor = [UIColor clearColor];
  101 + _slider.multipleTouchEnabled = NO;
  102 + [_slider setValue:[CNFontAndRatioTool getFontSizeCoefficient]];
  103 +
  104 + //添加点击手势和滑块滑动事件响应
  105 + [_slider addTarget:self action:@selector(valueChanged:) forControlEvents:UIControlEventValueChanged];
  106 + [_slider addTarget:self action:@selector(sliderTouchDown:) forControlEvents:UIControlEventTouchDown];
  107 + [_slider addTarget:self action:@selector(sliderTouchUp:) forControlEvents:UIControlEventTouchUpInside];
  108 +
  109 + self.tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapAction:)];
  110 + _tapGesture.delegate = self;
  111 + [self.slider addGestureRecognizer:self.tapGesture];
  112 + UIView *line = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-70-30, 1)];
  113 + line.center = _slider.center;
  114 + [bottomView addSubview:line];
  115 + line.backgroundColor = [UIColor grayColor];
  116 + //背景图
  117 + UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width-70-30, 8)];
  118 + imageView.center = self.slider.center;
  119 + UIImage *image = [self xw_getImageName:@"font_size_slider" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
  120 + imageView.image = image;
  121 + [bottomView addSubview:imageView];
  122 + [bottomView addSubview:self.slider];
  123 +
  124 + UILabel *leftLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x-3, 30, 30, 20)];
  125 + leftLabel.font = [UIFont systemFontOfSize:14];
  126 + leftLabel.text = @"A";
  127 + [bottomView addSubview:leftLabel];
  128 +
  129 + UILabel *standardLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width/5-6, 30, 50, 20)];
  130 + standardLabel.font = [UIFont systemFontOfSize:16];
  131 + standardLabel.text = @"标准";
  132 + standardLabel.textColor = [UIColor grayColor];
  133 + [bottomView addSubview:standardLabel];
  134 +
  135 + UILabel *rightLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageView.frame.origin.x+imageView.frame.size.width-7, 30, 30, 20)];
  136 + rightLabel.font = [UIFont systemFontOfSize:24];
  137 + rightLabel.text = @"A";
  138 + [bottomView addSubview:rightLabel];
  139 +
  140 +}
  141 +
  142 +- (void)didReceiveMemoryWarning {
  143 + [super didReceiveMemoryWarning];
  144 + // Dispose of any resources that can be recreated.
  145 +}
  146 +
  147 +- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
  148 + return self.data.count;
  149 +}
  150 +
  151 +- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
  152 + CNLiveMessageCell *cell = [tableView dequeueReusableCellWithIdentifier:@"CNLiveMessageCell"];
  153 + if (cell == nil) {
  154 + cell = [[CNLiveMessageCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"CNLiveMessageCell"];
  155 + }
  156 + CNLiveMessageFrame *messageFrame = self.data[indexPath.row];
  157 + cell.messageFrame = messageFrame;
  158 + return cell;
  159 +}
  160 +
  161 +- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
  162 + CNLiveMessageFrame *messageFrame = self.data[indexPath.row];
  163 + return messageFrame.cellHeight;
  164 +}
  165 +
  166 +#pragma mark - CNLiveSettingNavigationBarDelegate
  167 +- (void)navigationBar:(CNLiveSettingNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  168 + if ([actionEvents isEqualToString:@"1"]) {
  169 + [[NSUserDefaults standardUserDefaults] setInteger:tempCoefficient forKey:@"CNSizeFontCoefficient"];
  170 +
  171 + }else if ([actionEvents isEqualToString:@"2"]){
  172 + NSInteger temp = [[NSUserDefaults standardUserDefaults] integerForKey:@"CNSizeFontCoefficient"];
  173 + if (temp != tempCoefficient) {
  174 + [[NSNotificationCenter defaultCenter] postNotificationName:@"CNFONTSIZECHANGE" object:nil];
  175 + }
  176 + }
  177 + [self goBack];
  178 +
  179 +}
  180 +
  181 +#pragma mark - 懒加载
  182 +- (NSMutableArray *)data{
  183 + if (_data == nil) {
  184 + _data = [NSMutableArray array];
  185 + }
  186 + return _data;
  187 +}
  188 +
  189 +- (UITableView *)tableView{
  190 + if(!_tableView){
  191 + _tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, NavigationContentTop, self.view.frame.size.width, self.view.frame.size.height-130-NavigationContentTop) style:UITableViewStylePlain];
  192 + _tableView.separatorStyle = 0;
  193 + _tableView.backgroundColor = RGB(242, 242, 242);
  194 + _tableView.delegate = self;
  195 + _tableView.dataSource = self;
  196 + }
  197 + return _tableView;
  198 +}
  199 +
  200 +- (CNLiveSettingNavigationBar *)navigationBar {
  201 + if (!_navigationBar) {
  202 + _navigationBar = [[CNLiveSettingNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  203 + _navigationBar.backgroundColor = [UIColor whiteColor];
  204 + _navigationBar.delegate = self;
  205 + [_navigationBar.left setTitle:@"取消" forState:UIControlStateNormal];
  206 + [_navigationBar.left setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
  207 + [_navigationBar.left setImage:nil forState:UIControlStateNormal];
  208 + _navigationBar.title.text = @"设置字体大小";
  209 + [_navigationBar.right setTitle:@"完成" forState:UIControlStateNormal];
  210 + [_navigationBar.right setTitleColor:[UIColor colorWithRed:31/255.0 green:185/255.0 blue:34/255.0 alpha:1.0] forState:UIControlStateNormal];
  211 + [_navigationBar.right setTitleColor:[UIColor colorWithRed:63/255.0 green:109/255.0 blue:61/255.0 alpha:1.0] forState:UIControlStateSelected];
  212 + }
  213 + return _navigationBar;
  214 +}
  215 +
  216 +#pragma mark - 响应方法
  217 +- (void)goBack {
  218 + if (self.presentingViewController != nil) {
  219 + [self dismissViewControllerAnimated:YES completion:nil];
  220 + }
  221 + else {
  222 + [self.navigationController popViewControllerAnimated:YES];
  223 + }
  224 +}
  225 +
  226 +- (void)valueChanged:(UISlider *)sender {
  227 + //只取整数值,固定间距
  228 + NSString *tempStr = [self numberFormat:sender.value];
  229 + if (tempStr.floatValue == sender.value) {
  230 + return;
  231 + }
  232 + [sender setValue:tempStr.floatValue];
  233 + [self setFontCoefficient:tempStr.integerValue];
  234 +}
  235 +
  236 +/**
  237 + * 四舍五入
  238 + *
  239 + * @param num 待转换数字
  240 + *
  241 + * @return 转换后的数字
  242 + */
  243 +- (NSString *)numberFormat:(float)num {
  244 + NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
  245 + [formatter setPositiveFormat:@"0"];
  246 + return [formatter stringFromNumber:[NSNumber numberWithFloat:num]];
  247 +}
  248 +
  249 +- (void)setFontCoefficient:(NSInteger)coefficient{
  250 + [CNFontAndRatioTool setFontSizeCoefficient:coefficient];
  251 + for (CNLiveMessageFrame * frame in self.data) {
  252 + frame.message.content = frame.message.content;
  253 + [frame setMessage:frame.message];
  254 + }
  255 + [self.tableView reloadData];
  256 +
  257 +}
  258 +
  259 +- (void)tapAction:(UITapGestureRecognizer *)sender {
  260 + //取得点击点
  261 + CGPoint p = [sender locationInView:sender.view];
  262 + //计算处于背景图的几分之几,并将之转换为滑块的值(1~5)
  263 + float tempFloat = (p.x - 15 ) / (self.slider.frame.size.width-30) * 4 + 1;
  264 + NSString *tempStr = [self numberFormat:tempFloat];
  265 +
  266 + [self.slider setValue:tempStr.floatValue];
  267 + [self setFontCoefficient:tempStr.integerValue];
  268 +}
  269 +
  270 +- (void)sliderTouchDown:(UISlider *)sender {
  271 + _tapGesture.enabled = NO;
  272 +}
  273 +
  274 +- (void)sliderTouchUp:(UISlider *)sender {
  275 + _tapGesture.enabled = YES;
  276 +}
  277 +
  278 +/**
  279 + * 创建图片
  280 + *
  281 + * @param imageName 图片名字
  282 + * @param bundleName 图片所在的bundle名字
  283 + * @param targetClass 类和bundle的同级目录
  284 + * @return 返回UIImage
  285 + */
  286 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  287 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  288 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  289 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  290 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  291 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  292 +}
  293 +
  294 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageCell.h 0 → 100755
  1 +//
  2 +// CNLiveMessageCell.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@class CNLiveMessageFrame;
  12 +
  13 +@interface CNLiveMessageCell : UITableViewCell
  14 +
  15 +@property (nonatomic, strong) CNLiveMessageFrame *messageFrame;
  16 +
  17 +@end
  18 +
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageCell.m 0 → 100755
  1 +//
  2 +// CNLiveMessageCell.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveMessageCell.h"
  10 +#import "CNLiveMessageModel.h"
  11 +#import "CNLiveMessageFrame.h"
  12 +#import "CNLiveBaseKit.h"
  13 +#import "CNLiveMessageContentButton.h"
  14 +
  15 +@interface CNLiveMessageCell()
  16 +@property (nonatomic, strong) UIButton *btnHeadImage;//头像
  17 +@property (nonatomic, strong) CNLiveMessageContentButton *btnContent;//显示内容
  18 +
  19 +@end
  20 +
  21 +@implementation CNLiveMessageCell
  22 +
  23 +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  24 + self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  25 + if (self) {
  26 + self.backgroundColor = [UIColor clearColor];
  27 + self.selectionStyle = UITableViewCellSelectionStyleNone;
  28 +
  29 + self.btnHeadImage = [UIButton buttonWithType:UIButtonTypeCustom];
  30 + self.btnHeadImage.backgroundColor = [UIColor clearColor];
  31 + _btnHeadImage.layer.masksToBounds = YES;
  32 + UIImage *image = [self xw_getImageName:@"font_size_logo" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
  33 + [_btnHeadImage setBackgroundImage:image forState:UIControlStateNormal];
  34 + [self.contentView addSubview:self.btnHeadImage];
  35 +
  36 + self.btnContent = [[CNLiveMessageContentButton alloc]init];
  37 + [self.contentView addSubview:self.btnContent];
  38 +
  39 + }
  40 + return self;
  41 +}
  42 +
  43 +#pragma mark - 内容及Frame设置
  44 +- (void)setMessageFrame:(CNLiveMessageFrame *)messageFrame{
  45 + _messageFrame = messageFrame;
  46 + // 设置头像
  47 + self.btnHeadImage.frame = messageFrame.iconFrame;
  48 + // 4、设置内容
  49 + self.btnContent.messageFrame = messageFrame;//这里设置内容的frame等
  50 +
  51 +}
  52 +
  53 +/**
  54 + * 创建图片
  55 + *
  56 + * @param imageName 图片名字
  57 + * @param bundleName 图片所在的bundle名字
  58 + * @param targetClass 类和bundle的同级目录
  59 + * @return 返回UIImage
  60 + */
  61 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  62 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  63 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  64 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  65 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  66 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  67 +}
  68 +
  69 +@end
  70 +
  71 +
  72 +
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageContentButton.h 0 → 100755
  1 +//
  2 +// CNLiveMessageContentButton.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +#import "CNLiveMessageFrame.h"
  11 +#import "CNLiveMessageModel.h"
  12 +
  13 +@interface CNLiveMessageContentButton : UIButton
  14 +
  15 +@property (nonatomic, weak) UILabel *content;
  16 +
  17 +@property (nonatomic, strong) CNLiveMessageFrame *messageFrame;
  18 +
  19 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageContentButton.m 0 → 100755
  1 +//
  2 +// CNMessageContentButton.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveMessageContentButton.h"
  10 +#import "CNLiveBaseKit.h"
  11 +
  12 +@interface CNLiveMessageContentButton()
  13 +
  14 +@end
  15 +
  16 +@implementation CNLiveMessageContentButton
  17 +
  18 +- (id)initWithFrame:(CGRect)frame {
  19 + self = [super initWithFrame:frame];
  20 + if (self) {
  21 + [self createTextView];
  22 + }
  23 + return self;
  24 +}
  25 +
  26 +#pragma mark -文本视图
  27 +- (void)createTextView{
  28 + UILabel *content = [[UILabel alloc] init];
  29 + content.userInteractionEnabled = NO;
  30 + content.backgroundColor = [UIColor clearColor];
  31 + content.numberOfLines = 0;
  32 + content.lineBreakMode = NSLineBreakByWordWrapping;
  33 + content.font = UIFontCNMake(15);
  34 + [self addSubview:content];
  35 + self.content = content;
  36 +}
  37 +
  38 +- (void)setMessageFrame:(CNLiveMessageFrame *)messageFrame {
  39 + _messageFrame = messageFrame;
  40 + self.frame = messageFrame.contentFrame;
  41 + [self layoutSubviews];
  42 + //背景气泡图
  43 + UIImage *normal;
  44 + CNLiveMessageModel *message = messageFrame.message;
  45 +
  46 + if ([message.fromMe isEqualToString:@"1"]) {
  47 + normal = [self xw_getImageName:@"font_size_message_me" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
  48 + normal = [normal stretchableImageWithLeftCapWidth:normal.size.width * 0.5 topCapHeight:normal.size.height * 0.9];
  49 + }
  50 + else{
  51 + normal = [self xw_getImageName:@"font_size_message_other" bundleName:@"CNLiveSettingModule" targetClass:[self class]];
  52 + normal = [normal stretchableImageWithLeftCapWidth:normal.size.width * 0.5 topCapHeight:normal.size.height * 0.9];
  53 + }
  54 +
  55 + [self setBackgroundImage:normal forState:UIControlStateNormal];
  56 +
  57 + // 我发出的消息
  58 + if ([message.fromMe isEqualToString:@"1"]){
  59 + // 是我的消息
  60 + self.content.textColor = [UIColor whiteColor];
  61 + self.content.frame = CGRectMake(10, 15, self.frame.size.width-20, self.frame.size.height-30);
  62 + }
  63 + else {
  64 + // 不是我的消息
  65 + self.content.frame = CGRectMake(15, 15, self.frame.size.width-15, self.frame.size.height-30);
  66 +
  67 + }
  68 +
  69 + self.content.hidden = NO;
  70 + self.content.text = message.content;
  71 + self.content.font = UIFontCNMake(15);
  72 +
  73 +// self.backgroundColor = [UIColor redColor];
  74 +// self.textView.backgroundColor = [UIColor yellowColor];
  75 +
  76 +}
  77 +
  78 +- (BOOL)canBecomeFirstResponder{
  79 + return YES;
  80 +}
  81 +
  82 +/**
  83 + * 创建图片
  84 + *
  85 + * @param imageName 图片名字
  86 + * @param bundleName 图片所在的bundle名字
  87 + * @param targetClass 类和bundle的同级目录
  88 + * @return 返回UIImage
  89 + */
  90 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  91 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  92 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  93 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  94 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  95 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  96 +}
  97 +
  98 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageFrame.h 0 → 100755
  1 +//
  2 +// CNLiveMessageFrame.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +#define ChatMargin 10 //间隔
  9 +#define ChatIconWH 45 //头像宽高height、width
  10 +
  11 +#define ChatContentTop 15 //文本内容与按钮上边缘间隔
  12 +#define ChatContentLeft 10 //文本内容与按钮左边缘间隔
  13 +#define ChatContentBottom 15 //文本内容与按钮下边缘间隔
  14 +#define ChatContentRight 10 //文本内容与按钮右边缘间隔
  15 +
  16 +#import <Foundation/Foundation.h>
  17 +
  18 +@class CNLiveMessageModel;
  19 +
  20 +@interface CNLiveMessageFrame : NSObject
  21 +
  22 +@property (nonatomic, assign) CGRect iconFrame; // 头像frame
  23 +@property (nonatomic, assign) CGRect contentFrame; // 内容frame
  24 +@property (nonatomic, assign) CGFloat cellHeight; //cell 的高度
  25 +
  26 +@property (nonatomic, strong) CNLiveMessageModel *message;
  27 +
  28 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageFrame.m 0 → 100755
  1 +//
  2 +// CNLiveMessageFrame.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveMessageFrame.h"
  10 +#import "CNLiveMessageModel.h"
  11 +#import "QMUIKit.h"
  12 +#import "CNLiveBaseKit.h"
  13 +
  14 +@implementation CNLiveMessageFrame
  15 +
  16 +- (void)setMessage:(CNLiveMessageModel *)message{
  17 + _message = message;
  18 + // 1.计算头像位置
  19 + CGFloat iconX = ChatMargin;//头像边距
  20 + if ([_message.fromMe isEqualToString:@"1"]) {
  21 + iconX = SCREEN_WIDTH - ChatMargin - ChatIconWH;//头像坐标X
  22 + }
  23 + CGFloat iconY = ChatContentTop;//头像坐标Y
  24 + _iconFrame = CGRectMake(iconX, iconY, ChatIconWH, ChatIconWH);
  25 +
  26 + // 2.计算内容位置
  27 + CGFloat contentX = ChatIconWH+ChatMargin*2;
  28 + CGFloat contentY = iconY;
  29 +
  30 + CGSize maxSize = CGSizeMake(SCREEN_WIDTH-ChatIconWH*2-ChatMargin*2-(ChatContentLeft + ChatContentRight), CGFLOAT_MAX);
  31 + CGSize contentSize = [_message.content boundingRectWithSize:maxSize options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:UIFontCNMake(15)} context:nil].size;
  32 +
  33 + if ([_message.fromMe isEqualToString:@"1"]){
  34 + contentX = iconX - contentSize.width - ChatContentLeft - ChatContentRight-ChatMargin;
  35 + }
  36 + CGFloat h = 0;
  37 + if (contentSize.height + ChatContentTop + ChatContentBottom < ChatIconWH*RATIO) {
  38 + h = ChatIconWH;
  39 + }else{
  40 + h = contentSize.height + ChatContentTop + ChatContentBottom;
  41 + }
  42 + _contentFrame = CGRectMake(contentX, contentY, contentSize.width + 5 + ChatContentLeft + ChatContentRight, h);
  43 +
  44 + _cellHeight = MAX(CGRectGetMaxY(self.contentFrame), CGRectGetMaxY(self.iconFrame));
  45 +
  46 +}
  47 +
  48 +
  49 +@end
  50 +
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageModel.h 0 → 100755
  1 +//
  2 +// CNLiveMessageModel.h
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import <Foundation/Foundation.h>
  10 +
  11 +@interface CNLiveMessageModel :NSObject
  12 +@property (nonatomic, copy) NSString *fromMe; //是否自己发的
  13 +@property (nonatomic, copy) NSString *content; //消息内容
  14 +
  15 +@end
CNLiveSettingModule/Classes/FontSIze/CNLiveMessageModel.m 0 → 100755
  1 +//
  2 +// CNLiveMessageModel.m
  3 +// CNLiveSettingModule
  4 +//
  5 +// Created by open on 2018/9/1.
  6 +// Copyright © 2018年 cnlive. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveMessageModel.h"
  10 +
  11 +@implementation CNLiveMessageModel
  12 +
  13 +
  14 +@end
CNLiveSettingModule/Classes/View/CNLiveSettingNavigationBar.m
@@ -61,6 +61,7 @@ static const NSInteger margin = 15; @@ -61,6 +61,7 @@ static const NSInteger margin = 15;
61 _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight); 61 _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight);
62 UIImage *image = [self xw_getImageName:@"mine_back_black_b" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveSettingNavigationBar class]]; 62 UIImage *image = [self xw_getImageName:@"mine_back_black_b" bundleName:@"CNLiveSettingModule" targetClass:[CNLiveSettingNavigationBar class]];
63 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; 63 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  64 + _left.titleLabel.font = [UIFont systemFontOfSize:15];
64 [_left setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; 65 [_left setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
65 [_left addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside]; 66 [_left addTarget:self action:@selector(goBack) forControlEvents:UIControlEventTouchUpInside];
66 } 67 }
Example/CNLiveSettingModule.xcodeproj/project.pbxproj
@@ -306,6 +306,7 @@ @@ -306,6 +306,7 @@
306 inputPaths = ( 306 inputPaths = (
307 "${PODS_ROOT}/Target Support Files/Pods-CNLiveSettingModule_Example/Pods-CNLiveSettingModule_Example-frameworks.sh", 307 "${PODS_ROOT}/Target Support Files/Pods-CNLiveSettingModule_Example/Pods-CNLiveSettingModule_Example-frameworks.sh",
308 "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework", 308 "${BUILT_PRODUCTS_DIR}/AFNetworking/AFNetworking.framework",
  309 + "${BUILT_PRODUCTS_DIR}/CNLiveBaseKit/CNLiveBaseKit.framework",
309 "${BUILT_PRODUCTS_DIR}/CNLiveBeeHive/CNLiveBeeHive.framework", 310 "${BUILT_PRODUCTS_DIR}/CNLiveBeeHive/CNLiveBeeHive.framework",
310 "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework", 311 "${BUILT_PRODUCTS_DIR}/CNLiveEnvironment/CNLiveEnvironment.framework",
311 "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework", 312 "${BUILT_PRODUCTS_DIR}/CNLiveRequestBastKit/CNLiveRequestBastKit.framework",
@@ -322,6 +323,7 @@ @@ -322,6 +323,7 @@
322 name = "[CP] Embed Pods Frameworks"; 323 name = "[CP] Embed Pods Frameworks";
323 outputPaths = ( 324 outputPaths = (
324 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework", 325 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/AFNetworking.framework",
  326 + "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBaseKit.framework",
325 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBeeHive.framework", 327 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveBeeHive.framework",
326 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework", 328 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveEnvironment.framework",
327 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework", 329 "${TARGET_BUILD_DIR}/${FRAMEWORKS_FOLDER_PATH}/CNLiveRequestBastKit.framework",