164 lines
4.9 KiB
Objective-C
164 lines
4.9 KiB
Objective-C
//
|
|
// SellyCallStatsView.m
|
|
// SellyCloudSDK_Example
|
|
//
|
|
// Created by Caleb on 12/17/25.
|
|
// Copyright © 2025 Caleb. All rights reserved.
|
|
//
|
|
|
|
#import "SellyCallStatsView.h"
|
|
#import <Masonry/Masonry.h>
|
|
|
|
@interface SellyCallStatsView ()
|
|
|
|
@property (nonatomic, strong) UIView *containerView;
|
|
@property (nonatomic, strong) UILabel *bitrateLabel;
|
|
@property (nonatomic, strong) UILabel *videoFpsLabel;
|
|
@property (nonatomic, strong) UILabel *rttLabel;
|
|
@property (nonatomic, strong) UILabel *codecLabel;
|
|
@property (nonatomic, strong) UILabel *durationLabel;
|
|
@property (nonatomic, strong) UILabel *videoSizeLabel;
|
|
|
|
@property (nonatomic, strong) UIStackView *stackView;
|
|
|
|
@end
|
|
|
|
@implementation SellyCallStatsView
|
|
|
|
- (instancetype)initWithFrame:(CGRect)frame {
|
|
self = [super initWithFrame:frame];
|
|
if (self) {
|
|
[self setupUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (instancetype)initWithCoder:(NSCoder *)coder {
|
|
self = [super initWithCoder:coder];
|
|
if (self) {
|
|
[self setupUI];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)setupUI {
|
|
self.backgroundColor = [UIColor clearColor];
|
|
|
|
// 创建半透明背景容器
|
|
self.containerView = [[UIView alloc] init];
|
|
self.containerView.backgroundColor = [UIColor colorWithWhite:0.0 alpha:0.6];
|
|
self.containerView.layer.cornerRadius = 8;
|
|
self.containerView.clipsToBounds = YES;
|
|
[self addSubview:self.containerView];
|
|
|
|
// 创建垂直 StackView
|
|
self.stackView = [[UIStackView alloc] init];
|
|
self.stackView.axis = UILayoutConstraintAxisVertical;
|
|
self.stackView.distribution = UIStackViewDistributionFillEqually;
|
|
self.stackView.alignment = UIStackViewAlignmentLeading;
|
|
self.stackView.spacing = 4;
|
|
[self.containerView addSubview:self.stackView];
|
|
|
|
// 创建标签
|
|
self.durationLabel = [self createStatLabel];
|
|
self.bitrateLabel = [self createStatLabel];
|
|
self.videoFpsLabel = [self createStatLabel];
|
|
self.rttLabel = [self createStatLabel];
|
|
self.codecLabel = [self createStatLabel];
|
|
self.videoSizeLabel = [self createStatLabel];
|
|
|
|
// 添加到 StackView
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"时长:" label:self.durationLabel]];
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"码率:" label:self.bitrateLabel]];
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"帧率:" label:self.videoFpsLabel]];
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"RTT:" label:self.rttLabel]];
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"编码:" label:self.codecLabel]];
|
|
[self.stackView addArrangedSubview:[self createRowWithTitle:@"分辨率:" label:self.videoSizeLabel]];
|
|
|
|
// 布局
|
|
[self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self);
|
|
}];
|
|
|
|
[self.stackView mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.edges.equalTo(self.containerView).insets(UIEdgeInsetsMake(12, 12, 12, 12));
|
|
}];
|
|
}
|
|
|
|
- (UILabel *)createStatLabel {
|
|
UILabel *label = [[UILabel alloc] init];
|
|
label.textColor = [UIColor whiteColor];
|
|
label.font = [UIFont monospacedSystemFontOfSize:12 weight:UIFontWeightRegular];
|
|
label.text = @"--";
|
|
return label;
|
|
}
|
|
|
|
- (UIView *)createRowWithTitle:(NSString *)title label:(UILabel *)valueLabel {
|
|
UIView *row = [[UIView alloc] init];
|
|
|
|
UILabel *titleLabel = [[UILabel alloc] init];
|
|
titleLabel.text = title;
|
|
titleLabel.textColor = [UIColor colorWithWhite:1.0 alpha:0.7];
|
|
titleLabel.font = [UIFont systemFontOfSize:12 weight:UIFontWeightMedium];
|
|
[row addSubview:titleLabel];
|
|
|
|
[row addSubview:valueLabel];
|
|
|
|
[titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.centerY.equalTo(row);
|
|
make.width.mas_equalTo(60);
|
|
}];
|
|
|
|
[valueLabel mas_makeConstraints:^(MASConstraintMaker *make) {
|
|
make.leading.equalTo(titleLabel.mas_trailing).offset(4);
|
|
make.centerY.equalTo(row);
|
|
make.trailing.lessThanOrEqualTo(row).offset(-8);
|
|
}];
|
|
|
|
return row;
|
|
}
|
|
|
|
#pragma mark - Public Methods
|
|
|
|
- (void)updateBitrate:(NSString *)bitrate {
|
|
self.bitrateLabel.text = bitrate ?: @"--";
|
|
}
|
|
|
|
- (void)updateVideoFps:(NSString *)fps {
|
|
self.videoFpsLabel.text = fps ?: @"--";
|
|
}
|
|
|
|
- (void)updateRtt:(NSString *)rtt {
|
|
self.rttLabel.text = rtt ?: @"--";
|
|
}
|
|
|
|
- (void)updateCodec:(NSString *)codec {
|
|
self.codecLabel.text = codec ?: @"--";
|
|
}
|
|
|
|
- (void)updateDuration:(NSString *)duration {
|
|
self.durationLabel.text = duration ?: @"00:00";
|
|
}
|
|
|
|
- (void)updateVideoSize:(NSString *)videoSize {
|
|
self.videoSizeLabel.text = videoSize ?: @"--";
|
|
}
|
|
|
|
- (void)show {
|
|
self.hidden = NO;
|
|
self.alpha = 0;
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.alpha = 1.0;
|
|
}];
|
|
}
|
|
|
|
- (void)hide {
|
|
[UIView animateWithDuration:0.3 animations:^{
|
|
self.alpha = 0;
|
|
} completion:^(BOOL finished) {
|
|
self.hidden = YES;
|
|
}];
|
|
}
|
|
|
|
@end
|