iOS 毛玻璃效果
//
// AMBlurView.h
// blur
//
// Created by Dubai Pinto Castillo on 7/3/15.
// Copyright (c) 2013 Dubai All rights reserved.
//
#import <UIKit/UIKit.h>
@interface JCRBlurView : UIView
// Use the following property to set the tintColor. Set it to nil to reset.
@property (nonatomic, strong) UIColor *blurTintColor;
@end
//
// AMBlurView.m
// blur
//
// Created by Dubai Pinto Castillo on 7/3/15.
// Copyright (c) 2013 Dubai All rights reserved.
//
#import "JCRBlurView.h"
@interface JCRBlurView ()
@property (nonatomic, strong) UIToolbar *toolbar;
@end
@implementation JCRBlurView
- (instancetype)initWithCoder:(NSCoder *)aDecoder {
self = [super initWithCoder:aDecoder];
if (self) {
[self setup];
}
return self;
}
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setup];
}
return self;
}
- (instancetype)init
{
self = [super init];
if (self) {
[self setup];
}
return self;
}
- (void)setup {
// If we don‘t clip to bounds the toolbar draws a thin shadow on top
[self setClipsToBounds:YES];
if (![self toolbar]) {
[self setToolbar:[[UIToolbar alloc] initWithFrame:[self bounds]]];
[self.toolbar setTranslatesAutoresizingMaskIntoConstraints:NO];
[self insertSubview:[self toolbar] atIndex:0];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|[_toolbar]|"
options:0
metrics:0
views:NSDictionaryOfVariableBindings(_toolbar)]];
[self addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|[_toolbar]|"
options:0
metrics:0
views:NSDictionaryOfVariableBindings(_toolbar)]];
}
}
- (void) setBlurTintColor:(UIColor *)blurTintColor {
[self.toolbar setBarTintColor:blurTintColor];
}
@end
//
// SecondViewController.m
// 磨平Demo
//
// Created by Dubaion 15/4/13.
// Copyright (c) 2015年 Dubai. All rights reserved.
//
#import "SecondViewController.h"
#import "JCRBlurView.h"
@interface SecondViewController ()
@property (nonatomic,strong) JCRBlurView *blurView;
@property (strong, nonatomic) UIButton *btn;
@end
@implementation SecondViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor whiteColor];
self.btn = [UIButton buttonWithType:(UIButtonTypeSystem)];
self.btn.frame = CGRectMake(60, 80, 60, 40);
[self.btn setTitle:@"毛玻璃" forState:(UIControlStateNormal)];
[self.btn addTarget:self action:@selector(didBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
[self.view addSubview:self.btn];
UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:self.view.bounds];
iamgeView.image = [UIImage imageNamed:@"fish.jpg"];
[self.view addSubview:iamgeView];
[self setBlurView:[JCRBlurView new]];
[[self blurView] setFrame:CGRectMake(20.f, 20.f, [self.view bounds].size.width-40.f, [self.view bounds].size.height-40.f)];
[[self blurView] setAutoresizingMask:UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight];
[self.view addSubview:[self blurView]];
}
- (void)didBtnAction:(UIButton *)sender
{
NSLog(@"毛玻璃效果");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。