123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166 |
- //
- // FKUpdateTipView.m
- // FirstLink
- //
- // Created by ascii on 16/4/11.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKUpdateTipView.h"
- #import "FKWindowViewManager.h"
- @interface FKUpdateTipView ()
- @property (nonatomic, strong) UIImageView *bgImageView;
- @property (nonatomic, strong) UILabel *contentLabel;
- @property (nonatomic, strong) UIButton *confirmButton;
- @property (nonatomic, strong) UIButton *cancelButton;
- @property (nonatomic, strong) NSString *appUpdateURL;
- @end
- @implementation FKUpdateTipView
- /*
- // Only override drawRect: if you perform custom drawing.
- // An empty implementation adversely affects performance during animation.
- - (void)drawRect:(CGRect)rect {
- // Drawing code
- }
- */
- - (instancetype)init {
- self = [super init];
- if (self) {
- self.backgroundColor = [UIColor whiteColor];
- self.layer.cornerRadius = 8;
- }
- return self;
- }
- - (void)configViewWith:(FKUpdateType)type appUpdateURL:(NSString *)appUpdateURL content:(NSString *)content confirmTitle:(NSString *)confirmTitle cancelTitle:(NSString *)cancelTitle {
- [self addSubview:self.bgImageView];
- [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self).offset(35);
- }];
-
- self.contentLabel.text = content;
- [self addSubview:self.contentLabel];
- [self.contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.top.equalTo(self.bgImageView.mas_bottom).offset(16);
- make.width.mas_equalTo(160);
- }];
-
- if (type == FKUpdateTypeAdvise) {
- // cancel
- [self.cancelButton setTitle:cancelTitle forState:UIControlStateNormal];
- [self addSubview:self.cancelButton];
- [self.cancelButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.bottom.equalTo(self).offset(-32);
- make.size.mas_equalTo(CGSizeMake(160, 26));
- }];
-
- // confirm
- [self.confirmButton setTitle:confirmTitle forState:UIControlStateNormal];
- [self addSubview:self.confirmButton];
- [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.bottom.equalTo(self).offset(-74);
- make.size.mas_equalTo(CGSizeMake(160, 26));
- }];
- } else {
- // confirm
- [self.confirmButton setTitle:confirmTitle forState:UIControlStateNormal];
- [self addSubview:self.confirmButton];
- [self.confirmButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerX.equalTo(self);
- make.bottom.equalTo(self).offset(-48);
- make.size.mas_equalTo(CGSizeMake(160, 26));
- }];
- }
-
- self.appUpdateURL = appUpdateURL;
- }
- + (CGFloat)heightWith:(FKUpdateType)type
- content:(NSString *)content {
- if (content) {
- CGSize size = [FLStringHelper rectOfString:content
- font:[UIFont systemFontOfSize:14]
- width:160].size;
- CGFloat height = 0;
- if (type == FKUpdateTypeAdvise) {
- height = (135 + size.height + 128);
- }
- if (type == FKUpdateTypeForce) {
- height = (135 + size.height + 90);
- }
- return MAX(280, height);
- }
- return 100;
- }
- #pragma mark - Action
- - (IBAction)clickConfirmButton:(id)sender {
- if (self.appUpdateURL.length > 0) {
- [[UIApplication sharedApplication] openURL:[NSURL URLWithString:self.appUpdateURL]];
- }
- }
- - (IBAction)clickCancelButton:(id)sender {
- [[FKWindowViewManager sharedManager] closeFloatView];
- }
- #pragma mark - Property
- - (UIImageView *)bgImageView {
- if (!_bgImageView) {
- _bgImageView = [[UIImageView alloc] init];
- _bgImageView.image = [UIImage imageNamed:@"UpdateTipIcon"];
- }
- return _bgImageView;
- }
- - (UILabel *)contentLabel {
- if (!_contentLabel) {
- _contentLabel = [[UILabel alloc] init];
- _contentLabel.textColor = UIColorFromRGB(0x333333);
- _contentLabel.textAlignment = NSTextAlignmentCenter;
- _contentLabel.numberOfLines = 0;
- _contentLabel.font = [UIFont systemFontOfSize:14];
- }
- return _contentLabel;
- }
- - (UIButton *)confirmButton {
- if (!_confirmButton) {
- _confirmButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _confirmButton.backgroundColor = UIColorFromRGB(0xff6362);
- _confirmButton.layer.cornerRadius = 13;
- [_confirmButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
- [_confirmButton setTitleColor:UIColorFromRGB(0xffffff) forState:UIControlStateNormal];
- [_confirmButton addTarget:self action:@selector(clickConfirmButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _confirmButton;
- }
- - (UIButton *)cancelButton {
- if (!_cancelButton) {
- _cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
- _cancelButton.backgroundColor = UIColorFromRGB(0xeeeeee);
- _cancelButton.layer.cornerRadius = 13;
- [_cancelButton.titleLabel setFont:[UIFont systemFontOfSize:14]];
- [_cancelButton setTitleColor:UIColorFromRGB(0x999999) forState:UIControlStateNormal];
- [_cancelButton addTarget:self action:@selector(clickCancelButton:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _cancelButton;
- }
- @end
|