diff --git a/ILTranslucentView.podspec b/ILTranslucentView.podspec index e953f1e..995753b 100644 --- a/ILTranslucentView.podspec +++ b/ILTranslucentView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = 'ILTranslucentView' - s.version = '0.1' + s.version = '0.2' s.license = 'MIT' s.summary = 'ILTranslucentView is a little subclass of UIView that provide native iOS 7+ blur effect.' s.description = 'ILTranslucentView is a little subclass of UIView that provide native iOS 7+ blur (translucent) effect. It can be used on all iOS devices in real time without any performance problems. It also supports smooth UIView animation of color, frame, alpha etc.' @@ -11,4 +11,4 @@ Pod::Spec.new do |s| s.source_files = 'Source' s.requires_arc = true s.ios.deployment_target = '7.0' -end \ No newline at end of file +end diff --git a/README.md b/README.md index 4dcbf73..04416f8 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,8 @@ It can be used on all iOS devices in real time without any performance problems. - use it as normal UIView but with additional methods/propertiers: ```objective-c + #import "ILTranslucentView-Swift.h" + ILTranslucentView *translucentView = [[ILTranslucentView alloc] initWithFrame:CGRectMake(0, 0, 250, 150)]; [self.view addSubview:translucentView]; //that's it :) @@ -24,6 +26,8 @@ It can be used on all iOS devices in real time without any performance problems. ``` ```swift + import ILTranslucentView + var view = ILTranslucentView(frame: CGRectMake(0, 0, 250, 150)) self.view.addSubview(view) diff --git a/Source/ILTranslucentView.h b/Source/ILTranslucentView.h deleted file mode 100644 index f958157..0000000 --- a/Source/ILTranslucentView.h +++ /dev/null @@ -1,19 +0,0 @@ -// -// ILTranslucentView.h -// ILTranslucentViewProject -// -// Created by Ivo Leko on 10/11/13. -// Copyright (c) 2013 Ivo Leko. All rights reserved. -// - -#import - -@interface ILTranslucentView : UIView - -@property (nonatomic) BOOL translucent; //do you want blur effect? (default: YES) -@property (nonatomic) CGFloat translucentAlpha; //alpha of translucent effect (default: 1) -@property (nonatomic) UIBarStyle translucentStyle; //blur style, Default or Black -@property (nonatomic, strong) UIColor *translucentTintColor; //tint color of blur, [UIColor clearColor] is default - - -@end diff --git a/Source/ILTranslucentView.m b/Source/ILTranslucentView.m deleted file mode 100644 index 018ddff..0000000 --- a/Source/ILTranslucentView.m +++ /dev/null @@ -1,298 +0,0 @@ -// -// ILTranslucentView.m -// ILTranslucentViewProject -// -// Created by Ivo Leko on 10/11/13. -// Copyright (c) 2013 Ivo Leko. All rights reserved. -// - -#import "ILTranslucentView.h" -#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending) - -@interface ILTranslucentView () { - UIView *nonexistentSubview; //this is first child view of ILTranslucentView. It is not available trough "Managing the View Hierarchy" methods. - UIView *toolbarContainerClipView; //view which contain UIToolbar as child subview - UIToolbar *toolBarBG; //this is empty toolbar which we use to produce blur (translucent) effect - UIView *overlayBackgroundView; //view over toolbar that is responsive to backgroundColor property - BOOL initComplete; -} - -@property (nonatomic, copy) UIColor *ilColorBG; //backGround color -@property (nonatomic, copy) UIColor *ilDefaultColorBG; //default Apple's color of UIToolbar - -@end - -@implementation ILTranslucentView -@synthesize translucentAlpha = _translucentAlpha; - - -#pragma mark - Initalization -- (id)initWithFrame:(CGRect)frame //code -{ - self = [super initWithFrame:frame]; - if (self) { - [self createUI]; - } - return self; -} - -- (id) initWithCoder:(NSCoder *)aDecoder { //XIB - self = [super initWithCoder:aDecoder]; - if (self) { - [self createUI]; - } - return self; -} - - -- (void) createUI { - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { - _ilColorBG = self.backgroundColor; //get background color of view (can be set trough interface builder before) - self.ilDefaultColorBG=toolBarBG.barTintColor; //Apple's default background color - - _translucent=YES; - _translucentAlpha=1; - - // creating nonexistentSubview - nonexistentSubview = [[UIView alloc] initWithFrame:self.bounds]; - nonexistentSubview.backgroundColor=[UIColor clearColor]; - nonexistentSubview.clipsToBounds=YES; - nonexistentSubview.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; - [self insertSubview:nonexistentSubview atIndex:0]; - - //creating toolbarContainerClipView - toolbarContainerClipView = [[UIView alloc] initWithFrame:self.bounds]; - toolbarContainerClipView.backgroundColor=[UIColor clearColor]; - toolbarContainerClipView.clipsToBounds=YES; - toolbarContainerClipView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin; - [nonexistentSubview addSubview:toolbarContainerClipView]; - - //creating toolBarBG - //we must clip 1px line on the top of toolbar - CGRect rect= self.bounds; - rect.origin.y-=1; - rect.size.height+=1; - toolBarBG =[[UIToolbar alloc] initWithFrame:rect]; - toolBarBG.frame=rect; - toolBarBG.autoresizingMask= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [toolbarContainerClipView addSubview:toolBarBG]; - - - - - //view above toolbar, great for changing blur color effect - overlayBackgroundView = [[UIView alloc] initWithFrame:self.bounds]; - overlayBackgroundView.backgroundColor = self.backgroundColor; - overlayBackgroundView.autoresizingMask= UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; - [toolbarContainerClipView addSubview:overlayBackgroundView]; - - - [self setBackgroundColor:[UIColor clearColor]]; //view must be transparent :) - initComplete=YES; - } - -} - -#pragma mark - Configuring a View’s Visual Appearance - - - -- (BOOL) isItClearColor: (UIColor *) color { - CGFloat red = 0.0, green = 0.0, blue = 0.0, alpha =0.0; - [color getRed:&red green:&green blue:&blue alpha:&alpha]; - - if (red!=0 || green != 0 || blue != 0 || alpha != 0) { - return NO; - } - else { - return YES; - } -} - -- (void) setFrame:(CGRect)frame { - - - // - Setting frame of view - - // UIToolbar's frame is not great at animating. It produces lot of glitches. - // Because of that, we never actually reduce size of toolbar" - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { - CGRect rect = frame; - rect.origin.x=0; - rect.origin.y=0; - - if (toolbarContainerClipView.frame.size.width>rect.size.width) { - rect.size.width=toolbarContainerClipView.frame.size.width; - } - if (toolbarContainerClipView.frame.size.height>rect.size.height) { - rect.size.height=toolbarContainerClipView.frame.size.height; - } - - toolbarContainerClipView.frame=rect; - - [super setFrame:frame]; - [nonexistentSubview setFrame:self.bounds]; - } - else - [super setFrame:frame]; -} - -- (void) setBounds:(CGRect)bounds { - - // - Setting bounds of view - - // UIToolbar's bounds is not great at animating. It produces lot of glitches. - // Because of that, we never actually reduce size of toolbar" - - - if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { - CGRect rect = bounds; - rect.origin.x=0; - rect.origin.y=0; - - if (toolbarContainerClipView.bounds.size.width>rect.size.width) { - rect.size.width=toolbarContainerClipView.bounds.size.width; - } - if (toolbarContainerClipView.bounds.size.height>rect.size.height) { - rect.size.height=toolbarContainerClipView.bounds.size.height; - } - - toolbarContainerClipView.bounds=rect; - [super setBounds:bounds]; - [nonexistentSubview setFrame:self.bounds]; - } - else - [super setBounds:bounds]; - -} - - -- (void) setTranslucentStyle:(UIBarStyle)translucentStyle { - toolBarBG.barStyle=translucentStyle; -} -- (UIBarStyle) translucentStyle { - return toolBarBG.barStyle; -} - - -- (void) setTranslucentTintColor:(UIColor *)translucentTintColor { - - _translucentTintColor = translucentTintColor; - - //tint color of toolbar - if ([self isItClearColor:translucentTintColor]) - [toolBarBG setBarTintColor:self.ilDefaultColorBG]; - else - [toolBarBG setBarTintColor:translucentTintColor]; -} - -- (void) setBackgroundColor:(UIColor *)backgroundColor { - - //changing backgroundColor of view actually change tintColor of toolbar - if (initComplete) { - - self.ilColorBG=backgroundColor; - if (_translucent) { - overlayBackgroundView.backgroundColor = backgroundColor; - [super setBackgroundColor:[UIColor clearColor]]; - } - else { - [super setBackgroundColor:self.ilColorBG]; - } - - } - else - [super setBackgroundColor:backgroundColor]; -} - -- (void) setTranslucent:(BOOL)translucent { - - //enabling and disabling blur effect - _translucent=translucent; - - toolBarBG.translucent=translucent; - if (translucent) { - toolBarBG.hidden=NO; - [toolBarBG setBarTintColor:self.ilColorBG]; - [self setBackgroundColor:[UIColor clearColor]]; - } - else { - toolBarBG.hidden=YES; - [self setBackgroundColor:self.ilColorBG]; - } -} - -- (void) setTranslucentAlpha:(CGFloat)translucentAlpha { - //changing alpha of toolbar - - if (translucentAlpha>1) - _translucentAlpha=1; - else if (translucentAlpha<0) - _translucentAlpha=0; - else - _translucentAlpha=translucentAlpha; - - toolBarBG.alpha=translucentAlpha; - -} - - -#pragma mark - Managing the View Hierarchy - -- (NSArray *) subviews { - - // must exclude nonexistentSubview - - if (initComplete) { - NSMutableArray *array = [NSMutableArray arrayWithArray:[super subviews]]; - [array removeObject:nonexistentSubview]; - return (NSArray *)array; - } - else { - return [super subviews]; - } - -} -- (void) sendSubviewToBack:(UIView *)view { - - // must exclude nonexistentSubview - - if (initComplete) { - [self insertSubview:view aboveSubview:toolbarContainerClipView]; - return; - } - else - [super sendSubviewToBack:view]; -} -- (void) insertSubview:(UIView *)view atIndex:(NSInteger)index { - - // must exclude nonexistentSubview - - if (initComplete) { - [super insertSubview:view atIndex:(index+1)]; - } - else - [super insertSubview:view atIndex:index]; - -} -- (void) exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2 { - - // must exclude nonexistentSubview - - if (initComplete) - [super exchangeSubviewAtIndex:(index1+1) withSubviewAtIndex:(index2+1)]; - else - [super exchangeSubviewAtIndex:(index1) withSubviewAtIndex:(index2)]; -} - - -/* -// Only override drawRect: if you perform custom drawing. -// An empty implementation adversely affects performance during animation. -- (void)drawRect:(CGRect)rect -{ - // Drawing code -} -*/ - -@end diff --git a/Source/ILTranslucentView.swift b/Source/ILTranslucentView.swift index bada3af..21feca6 100755 --- a/Source/ILTranslucentView.swift +++ b/Source/ILTranslucentView.swift @@ -96,7 +96,7 @@ public class ILTranslucentView: UIView { private var overlayBackgroundView : UIView? private var initComplete = false - override init(frame: CGRect) { + public override init(frame: CGRect) { super.init(frame: frame) self.createUI() }