// // MyCardVC.m // smartRhino // // Created by niuzhen on 2020/4/29. // Copyright © 2020 tederen. All rights reserved. // #import "MyCardVC.h" #import "PayAlert.h" @interface MyCardVC () @property (weak, nonatomic) IBOutlet UIButton *rightBtn; @property (weak, nonatomic) IBOutlet UILabel *NameL; @property (weak, nonatomic) IBOutlet UILabel *timeL; @property (weak, nonatomic) IBOutlet UIButton *BookBtn; @property (weak, nonatomic) IBOutlet UIButton *ListenBtn; @property (weak, nonatomic) IBOutlet UIButton *ManBtn; @property (weak, nonatomic) IBOutlet UIButton *NetBtn; @property (weak, nonatomic) IBOutlet UIView *timeView; @property (weak, nonatomic) IBOutlet NSLayoutConstraint *timeConstant; @property (weak, nonatomic) IBOutlet UIView *subTitleView; @property (weak, nonatomic) IBOutlet UIButton *PayBtn; @property (weak, nonatomic) IBOutlet UIButton *ServiceBtn; @end @implementation MyCardVC +(MyCardVC *)initMyCardVC{ MyCardVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"MyCardVC"]; return controller; } - (void)viewDidLoad { [super viewDidLoad]; self.fd_prefersNavigationBarHidden = YES; [self setTimeLColor]; [self setSubTitleColor]; [self setPayBtnColor]; [self setServiceColor]; [self.rightBtn setAction:^{ }]; [self.PayBtn setAction:^{ [[PayAlert share] show]; }]; [self.ServiceBtn setAction:^{ }]; } - (void)setTimeLColor { self.timeL.text = @" 免费试用 · 5月28日到期 "; CGFloat W = [self.timeL sizeThatFits:CGSizeMake(SCREEN_WIDTH, 24)].width; self.timeConstant.constant = W; CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)UIColorHex(0xD4A75A).CGColor, (__bridge id)UIColorHex(0xE5C182).CGColor]; gradientLayer.locations = @[@0.0, @1.0]; gradientLayer.startPoint = CGPointMake(0, 0); gradientLayer.endPoint = CGPointMake(1.0, 0); gradientLayer.frame = CGRectMake(0, 0, W, 24); [self.timeView.layer addSublayer:gradientLayer]; UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, W, 24) byRoundingCorners:UIRectCornerBottomLeft|UIRectCornerTopLeft cornerRadii:CGSizeMake(12, 12)]; CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init]; maskLayer.frame = self.timeL.bounds; maskLayer.path = maskPath.CGPath; self.timeView.layer.mask = maskLayer; } - (void)setSubTitleColor { CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)UIColorHex(0x51A2DB).CGColor, (__bridge id)UIColorHex(0x73B9EA).CGColor]; gradientLayer.locations = @[@0.0, @1.0]; gradientLayer.startPoint = CGPointMake(0, 0); gradientLayer.endPoint = CGPointMake(1.0, 0); gradientLayer.frame = CGRectMake(0, 0, SCREEN_WIDTH - 32, 40); [self.subTitleView.layer addSublayer:gradientLayer]; } - (void)setPayBtnColor { CAGradientLayer *gradientLayer = [CAGradientLayer layer]; gradientLayer.colors = @[(__bridge id)UIColorHex(0xD6B178).CGColor, (__bridge id)UIColorHex(0xFEDCA9).CGColor]; gradientLayer.locations = @[@0.0, @1.0]; gradientLayer.startPoint = CGPointMake(0, 0); gradientLayer.endPoint = CGPointMake(1.0, 0); gradientLayer.frame = CGRectMake(0, 0, SCREEN_WIDTH - 32, 48); gradientLayer.cornerRadius = 12; [self.PayBtn.layer addSublayer:gradientLayer]; } - (void)setServiceColor { NSString * str = @" 已阅读并同意 会员订阅服务条款"; NSTextAttachment * attchment = [[NSTextAttachment alloc] init]; attchment.bounds = CGRectMake(0, -2, 12, 12); attchment.image = IMG(@"mine_agree_icon"); NSInteger location = 8; NSInteger lenght = 8; NSAttributedString * attstr = [NSAttributedString attributedStringWithAttachment:attchment]; NSMutableAttributedString * mstr = [[NSMutableAttributedString alloc] init]; [mstr appendAttributedString:attstr]; NSMutableAttributedString * textStr = [[NSMutableAttributedString alloc] initWithString:str]; [textStr addAttribute:NSForegroundColorAttributeName value:UIColorHex(0x666666) range:NSMakeRange(0, str.length)]; [textStr addAttribute:NSUnderlineStyleAttributeName value:@(NSUnderlineStyleSingle) range:NSMakeRange(location, lenght)]; [textStr addAttribute:NSUnderlineColorAttributeName value:UIColorHex(0x3D95EE) range:NSMakeRange(location, lenght)]; [textStr addAttribute:NSForegroundColorAttributeName value:UIColorHex(0x3D95EE) range:NSMakeRange(location, lenght)]; [mstr appendAttributedString:textStr]; [self.ServiceBtn setAttributedTitle:mstr forState:UIControlStateNormal]; } @end