// // TPLightView.m // ThePaperBase // // Created by zhousan on 15/12/29. // Copyright © 2015年 scar1900. All rights reserved. // #import "TPLightView.h" #import "UIImage+ImageEffects.h" @interface TPLightView () @property (nonatomic, strong) UIImageView *lightIcon; @property (nonatomic, strong) UIView *lightSlider; @property (nonatomic, strong) UILabel *titleLabel; @end @implementation TPLightView - (id)initWithValue:(int)value { self = [super initWithFrame:CGRectMake(0, 0, 155, 155)]; if (nil != self) { self.layer.cornerRadius = 8; self.layer.masksToBounds = YES; if (isIOS7) { self.backgroundColor = [UIColor whiteColor]; }else { UIBlurEffect *blurEffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight]; // 毛玻璃view 视图 UIVisualEffectView *effectView = [[UIVisualEffectView alloc] initWithEffect:blurEffect]; //添加到要有毛玻璃特效的控件中 effectView.frame = self.bounds; [self addSubview:effectView]; //设置模糊透明度 effectView.alpha = .8f; } [self addSubview:self.titleLabel]; [self addSubview:self.lightIcon]; [self addSubview:self.lightSlider]; [self.titleLabel makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.centerX); make.top.equalTo(self.top).offset(23/2); make.size.mas_equalTo(CGSizeMake(100, 16)); }]; [self.lightIcon makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self); make.centerY.equalTo(self); make.size.mas_equalTo(CGSizeMake(88, 88)); }]; [self.lightSlider makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.left).offset(13); make.bottom.equalTo(self.bottom).offset(-31/2); make.size.mas_equalTo(CGSizeMake(129, 7)); }]; for (int i = 0; i < 16; i++) { UIView *view = [[UIView alloc] initWithFrame:CGRectZero]; view.backgroundColor = [UIColor whiteColor]; view.tag = i+10; [self addSubview:view]; [view makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.lightSlider).offset(1+i*8); make.top.equalTo(self.lightSlider).offset(1); make.size.mas_equalTo(CGSizeMake(7, 5)); }]; } [self setValue:value]; } return self; } - (UIImageView *)lightIcon { if (nil == _lightIcon) { _lightIcon = [[UIImageView alloc] initWithFrame:CGRectZero]; _lightIcon.image = [UIImage imageNamed:@"lightIcon.png"]; } return _lightIcon; } - (UILabel *)titleLabel { if (nil == _titleLabel) { _titleLabel = [[UILabel alloc] initWithFrame:CGRectZero]; _titleLabel.text = @"亮度"; _titleLabel.textColor = [UIColor colorWithHexString:@"0x3d3d3d"]; _titleLabel.font = [UIFont systemFontOfSize:15]; _titleLabel.textAlignment = NSTextAlignmentCenter; } return _titleLabel; } - (UIView *)lightSlider { if (nil == _lightSlider) { _lightSlider = [[UIView alloc] initWithFrame:CGRectZero]; _lightSlider.backgroundColor = [UIColor colorWithHexString:@"0x3d3d3d"]; } return _lightSlider; } - (void)setValue:(int)value { for (int i=0; i