如题
上代码
#pragma mark ------ - 创建 tableview的headview ----
- (UIView *)creadTableViewHeadView{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSInteger selectedBook = [defaults integerForKey:@"selectedBook"];//读取当前阅读书籍
//创建 tableview的headview 展示当前阅读的书 以及进度
UIView * headView = [[UIView alloc]initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH, screen_height/3-20)];
UIImageView * imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 20, SCREEN_WIDTH/2-60, screen_height/3-60)];
[imageView sd_setImageWithURL:[NSURL URLWithString:_dataArray[1][selectedBook]]];
///////////////***冲突*************////////
// headView 模糊背景效果
// UIBlurEffect *beffect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleExtraLight];
//
// UIVisualEffectView *view = [[UIVisualEffectView alloc]initWithEffect:beffect];
//
// view.frame = headView.bounds;
//
//
// headView.backgroundColor = [UIColor colorWithPatternImage:imageView.image];
// [headView addSubview:view];
//
更改后的代码 调用以下方法
//生成一张毛玻璃图片 将图片设为背景颜色
/*
- (UIImage*)blur:(UIImage*)theImage
{
CIContext *context = [CIContext contextWithOptions:nil];
CIImage *inputImage = [CIImage imageWithCGImage:theImage.CGImage];
CIFilter *filter = [CIFilter filterWithName:@"CIGaussianBlur"];
[filter setValue:inputImage forKey:kCIInputImageKey];
[filter setValue:[NSNumber numberWithFloat:15.0f] forKey:@"inputRadius"];
CIImage *result = [filter valueForKey:kCIOutputImageKey];
CGImageRef cgImage = [context createCGImage:result fromRect:[inputImage extent]];
UIImage *returnImage = [UIImage imageWithCGImage:cgImage];
CGImageRelease(cgImage);
return returnImage;
}
*/
UILabel * headViewLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2-20, 40, 140, 30)];
headViewLabel.text = _dataArray[0][selectedBook];
//阅读进度 label
UILabel * progressLabel = [[UILabel alloc]initWithFrame:CGRectMake(SCREEN_WIDTH/2+60, (screen_height/3-20)/2, 100, 30)];
float bookReadingProgress = [defaults floatForKey:[NSString stringWithFormat:@"bookReadingProgress%ld",[_dataArray[2][selectedBook] integerValue]]];//读取当前阅读书籍进度
progressLabel.text = [[NSString stringWithFormat:@"%.2f",bookReadingProgress*100] stringByAppendingString:@"%"];
//进度条在左 详细进度百分比在右
UIProgressView * progressView = [[UIProgressView alloc]initWithProgressViewStyle:UIProgressViewStyleDefault];
progressView.frame = CGRectMake(SCREEN_WIDTH/2-20, (screen_height/3-20)/2+10, 40, 10);
progressView.progress = bookReadingProgress;
[headView addSubview:progressView];
//继续阅读按钮
UIButton * continueReadingButton = [[UIButton alloc]initWithFrame:CGRectMake(SCREEN_WIDTH-100 , screen_height/3-60, 80, 40)];
[continueReadingButton setTitle:@"继续阅读" forState:UIControlStateNormal];
[continueReadingButton addTarget:self action:@selector(continueReading) forControlEvents:UIControlEventTouchUpInside];
[headView addSubview:continueReadingButton];
[headView addSubview:progressLabel];
[headView addSubview:headViewLabel];
[headView addSubview:imageView];
//封面旋转效果
CATransform3D transform = CATransform3DIdentity;
//apply perspective
transform.m34 = - 1.0 / 500.0;
//rotate by 45 degrees along the Y axis
transform = CATransform3DRotate(transform, -M_PI/6,0, 1, 0);
//apply to layer
imageView.layer.transform = transform;
//
return headView;
}
网友评论