|
@@ -0,0 +1,104 @@
|
|
|
+//
|
|
|
+// KSStatusView.m
|
|
|
+// MusicGradeExam
|
|
|
+//
|
|
|
+// Created by Kyle on 2020/8/4.
|
|
|
+// Copyright © 2020 DayaMusic. All rights reserved.
|
|
|
+//
|
|
|
+
|
|
|
+#import "KSStatusView.h"
|
|
|
+
|
|
|
+@interface KSStatusView ()
|
|
|
+{
|
|
|
+ UIImageView *_imgView;
|
|
|
+}
|
|
|
+
|
|
|
+@property (nonatomic, strong) UIButton *actionButton;
|
|
|
+
|
|
|
+@property (nonatomic, copy) ActionCallback callback;
|
|
|
+
|
|
|
+@end
|
|
|
+
|
|
|
+@implementation KSStatusView
|
|
|
+
|
|
|
+- (instancetype)init {
|
|
|
+ self = [super init];
|
|
|
+ if (self) {
|
|
|
+ _desLabel = [[UILabel alloc] init];
|
|
|
+ _desLabel.font = [UIFont systemFontOfSize:17.0f];
|
|
|
+ _desLabel.textColor = HexRGB(0x999999);
|
|
|
+ _desLabel.textAlignment = NSTextAlignmentCenter;
|
|
|
+ _desLabel.numberOfLines = 1;
|
|
|
+ [self addSubview:_desLabel];
|
|
|
+
|
|
|
+ _imgView = [[UIImageView alloc] init];
|
|
|
+ [_imgView sizeToFit];
|
|
|
+ [self addSubview:_imgView];
|
|
|
+ }
|
|
|
+ return self;
|
|
|
+}
|
|
|
+
|
|
|
+-(void)layoutSubviews
|
|
|
+{
|
|
|
+ _desLabel.center = CGPointMake(self.center.x, self.center.y);
|
|
|
+ _imgView.center = CGPointMake(self.center.x, self.center.y - 130);
|
|
|
+ _actionButton.center = CGPointMake(self.center.x, CGRectGetMaxY(self.desLabel.frame)+30);
|
|
|
+}
|
|
|
+
|
|
|
+-(void)setText:(NSString *)strText
|
|
|
+{
|
|
|
+ _desLabel.text = strText;
|
|
|
+ [_desLabel sizeToFit];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)setImageName:(NSString *)imageName {
|
|
|
+ _imageName = imageName;
|
|
|
+ [_imgView setImage:[UIImage imageNamed:imageName]];
|
|
|
+ [_imgView sizeToFit];
|
|
|
+}
|
|
|
+
|
|
|
+- (void)showButtonAction:(NSString *)buttonTitle callback:(ActionCallback)callback {
|
|
|
+ if (callback) {
|
|
|
+ self.callback = callback;
|
|
|
+ }
|
|
|
+ CGFloat width = [self getButtonWidth:buttonTitle];
|
|
|
+ if (_actionButton) {
|
|
|
+ [_actionButton removeFromSuperview];
|
|
|
+ [_actionButton setTitle:buttonTitle forState:UIControlStateNormal];
|
|
|
+ _actionButton.frame = CGRectMake(0, 0, width, 30);
|
|
|
+ [self addSubview:_actionButton];
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ _actionButton = [UIButton buttonWithType:UIButtonTypeCustom];
|
|
|
+ [_actionButton setTitleColor:THEMECOLOR forState:UIControlStateNormal];
|
|
|
+ [_actionButton.titleLabel setFont:[UIFont systemFontOfSize:13.0f]];
|
|
|
+ [_actionButton setTitle:buttonTitle forState:UIControlStateNormal];
|
|
|
+ _actionButton.frame = CGRectMake(0, 0, width, 30);
|
|
|
+ _actionButton.layer.cornerRadius = 15.0f;
|
|
|
+ _actionButton.layer.borderWidth = 1.0f;
|
|
|
+ _actionButton.layer.borderColor = THEMECOLOR.CGColor;
|
|
|
+ [_actionButton addTarget:self action:@selector(buttonClickAction) forControlEvents:UIControlEventTouchUpInside];
|
|
|
+ [self addSubview:_actionButton];
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+- (CGFloat)getButtonWidth:(NSString *)buttonTitle {
|
|
|
+ return [buttonTitle boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, 30) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:13.0f]} context:nil].size.width + 24;
|
|
|
+}
|
|
|
+
|
|
|
+- (void)buttonClickAction {
|
|
|
+ if (self.callback) {
|
|
|
+ self.callback();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+/*
|
|
|
+// Only override drawRect: if you perform custom drawing.
|
|
|
+// An empty implementation adversely affects performance during animation.
|
|
|
+- (void)drawRect:(CGRect)rect {
|
|
|
+ // Drawing code
|
|
|
+}
|
|
|
+*/
|
|
|
+
|
|
|
+@end
|