You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
100 lines
3.3 KiB
100 lines
3.3 KiB
#import "PlayerView.h"
|
|
|
|
@interface PlayerView ()
|
|
|
|
@property(nonatomic, strong) UILabel *titleLabel;
|
|
@property(nonatomic, strong) UILabel *langLabel;
|
|
@property(nonatomic, strong) UILabel *cnLabel;
|
|
@property(nonatomic, strong) UILabel *enLabel;
|
|
@property(nonatomic, strong) UIStackView *stackView;
|
|
|
|
@end
|
|
|
|
@implementation PlayerView
|
|
|
|
- (instancetype)init {
|
|
if (self = [super init]) {
|
|
self.backgroundColor = [UIColor whiteColor];
|
|
|
|
UILabel *title = [[UILabel alloc] init];
|
|
title.text = @"实时翻译";
|
|
title.font = [UIFont boldSystemFontOfSize:22];
|
|
title.textColor = [UIColor blackColor];
|
|
title.textAlignment = NSTextAlignmentCenter;
|
|
title.numberOfLines = 1;
|
|
self.titleLabel = title;
|
|
|
|
UILabel *lang = [[UILabel alloc] init];
|
|
lang.text = @"中文(简体) -> 英语";
|
|
lang.font = [UIFont systemFontOfSize:14];
|
|
lang.textColor = [UIColor darkGrayColor];
|
|
lang.textAlignment = NSTextAlignmentLeft;
|
|
lang.numberOfLines = 1;
|
|
self.langLabel = lang;
|
|
|
|
UILabel *cn = [[UILabel alloc] init];
|
|
cn.font = [UIFont systemFontOfSize:18];
|
|
cn.textColor = [UIColor blackColor];
|
|
cn.textAlignment = NSTextAlignmentLeft;
|
|
cn.numberOfLines = 0;
|
|
self.cnLabel = cn;
|
|
|
|
UILabel *en = [[UILabel alloc] init];
|
|
en.font = [UIFont systemFontOfSize:18];
|
|
en.textColor = [UIColor colorWithRed:0.24 green:0.54 blue:0.90 alpha:1.0];
|
|
en.textAlignment = NSTextAlignmentLeft;
|
|
en.numberOfLines = 0;
|
|
self.enLabel = en;
|
|
|
|
NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
|
|
para.lineSpacing = 4;
|
|
|
|
self.cnLabel.attributedText = [[NSAttributedString alloc] initWithString:@"正在识别..." attributes:@{NSParagraphStyleAttributeName: para}];
|
|
|
|
self.enLabel.attributedText = [[NSAttributedString alloc] initWithString:@"翻译中..." attributes:@{NSParagraphStyleAttributeName: para}];
|
|
|
|
UIStackView *stack = [[UIStackView alloc] initWithArrangedSubviews:@[self.titleLabel, self.langLabel, self.cnLabel, self.enLabel]];
|
|
stack.axis = UILayoutConstraintAxisVertical;
|
|
stack.spacing = 12;
|
|
stack.alignment = UIStackViewAlignmentFill;
|
|
stack.distribution = UIStackViewDistributionFill;
|
|
stack.translatesAutoresizingMaskIntoConstraints = NO;
|
|
self.stackView = stack;
|
|
|
|
self.layoutMargins = UIEdgeInsetsMake(16, 16, 16, 16);
|
|
[self addSubview:self.stackView];
|
|
|
|
UILayoutGuide *guide = self.layoutMarginsGuide;
|
|
[NSLayoutConstraint activateConstraints:@[
|
|
[self.stackView.topAnchor constraintEqualToAnchor:guide.topAnchor],
|
|
[self.stackView.leadingAnchor constraintEqualToAnchor:guide.leadingAnchor],
|
|
[self.stackView.trailingAnchor constraintEqualToAnchor:guide.trailingAnchor],
|
|
[self.stackView.bottomAnchor constraintLessThanOrEqualToAnchor:guide.bottomAnchor]
|
|
]];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
- (void)play {
|
|
|
|
}
|
|
|
|
- (void)pause {
|
|
|
|
}
|
|
|
|
- (void)updateWithLang:(NSString *)lang cn:(NSString *)cn en:(NSString *)en {
|
|
if (lang != nil) {
|
|
self.langLabel.text = lang;
|
|
}
|
|
NSMutableParagraphStyle *para = [[NSMutableParagraphStyle alloc] init];
|
|
para.lineSpacing = 4;
|
|
if (cn != nil) {
|
|
self.cnLabel.attributedText = [[NSAttributedString alloc] initWithString:cn attributes:@{NSParagraphStyleAttributeName: para}];
|
|
}
|
|
if (en != nil) {
|
|
self.enLabel.attributedText = [[NSAttributedString alloc] initWithString:en attributes:@{NSParagraphStyleAttributeName: para}];
|
|
}
|
|
}
|
|
|
|
@end
|
|
|