实现毛玻璃效果

iOS7以来,应用界面上的设计很多都采用了毛玻璃效果

苹果也放出了实现毛玻璃的分类

有需要的直接搜索下面的关键字~

UIImage+ImageEffects.h,简单明了,好看好用

#import <UIKit/UIKit.h>

@interface UIImage (ImageEffects)

- (UIImage *)applyLightEffect;
- (UIImage *)applyExtraLightEffect;
- (UIImage *)applyDarkEffect;
- (UIImage *)applyTintEffectWithColor:(UIColor *)tintColor;

- (UIImage *)applyBlurWithRadius:(CGFloat)blurRadius tintColor:(UIColor *)tintColor saturationDeltaFactor:(CGFloat)saturationDeltaFactor maskImage:(UIImage *)maskImage;

@end

 

还有一种就是直接拿NavigationBar的效果自己封装一个视图(跟一个同学聊天的的时候他教我的~)

@interface SlurImageView ()
@property (nonatomic, strong) UINavigationBar *slurNavigationbar;
@end



@implementation SlurImageView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        
        [self setup];
        
    }
    return self;
}

-(void)awakeFromNib{
    [self setup];
}

- (void)setup
{
    // If we don't clip to bounds the toolbar draws a thin shadow on top
    [self setClipsToBounds:YES];
    
    if (!self.slurNavigationbar)
    {
        UINavigationBar *navigationBar = [[UINavigationBar alloc] initWithFrame:[self bounds]];
        self.slurNavigationbar = navigationBar;
        [self.layer insertSublayer:self.slurNavigationbar.layer atIndex:0];
    }
}


- (void)layoutSubviews
{
    [super layoutSubviews];
    
    [self.slurNavigationbar setFrame:[self bounds]];
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end

 

 

iOS8下苹果直接提供了实现毛玻璃效果的API

UIBlurEffectStyle

UIBlurEffectStyleView

看这里:::::   http://www.swiftmi.com/topic/77.html

 

posted @ 2014-10-17 15:49  784692237  阅读(684)  评论(0编辑  收藏  举报