반응형
UIViewControll+OverlayView.h
1 2 3 4 5 6 7 | #import <UIKit/UIKit.h> @interface UIViewController (OverlayView) -( void )showLayer:( NSString *)message; -( void )hideLayer; @end |
UIViewController+OverlayView.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | #import "UIViewController+OverlayView.h" @implementation UIViewController (OverlayView) -( void )showLayer:( NSString *)message { UIView *layer = [[ UIView alloc ] initWithFrame : self .view.bounds]; // layer.alpha = 0.5; layer.backgroundColor = [[ UIColor clearColor ] colorWithAlphaComponent :0 .5 ]; /* Create Label */ UILabel *label = [[ UILabel alloc ] initWithFrame : self .view.bounds]; label.textAlignment = UITextAlignmentCenter ; label.lineBreakMode = YES ; // 개행 설정. label.numberOfLines = 0 ; // 개행 숫자에 제한을 두지 않음. label.backgroundColor = [ UIColor clearColor ]; label.textColor = [ UIColor whiteColor ]; label.text = message; [layer addSubview :label]; [label release ]; /* Add LayerView */ [ self .view addSubview :layer]; [layer release ]; } -( void )hideLayer { NSArray *subViews = [ self .view subviews ]; UIView *layer = [subViews lastObject ]; [layer removeFromSuperview ]; } @end |
※ alpha 를 적용하게되면, UIView *layer 에 올라오는 컨트롤 및 서브뷰들도 해당 alpha value 가 적용되어 보여진다. 반면, backgroundColor 는 해당 View 에만 alpha value 가 적용된다.
USING CATEGORY
ViewController.m
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #import "ViewController.h" #import "UIViewController+OverlayView.h" @implementation ViewController - ( IBAction )onBtnAction:( id )sender { [ self showLayer : @ "MESSAGE TO SHOW" ]; [ self performSelector : @selector (onHideLayer) withObject : nil afterDelay :2 .0f ]; } - ( void )onHideLayer { [ self hideLayer ]; } @end |
- See more at: http://metalkin.tistory.com/47#sthash.iVctJirU.dpuf
반응형
'Developer > IOS' 카테고리의 다른 글
로딩 시간 조절 (0) | 2013.08.20 |
---|---|
view handle (0) | 2013.08.12 |
문자열 정리 (0) | 2013.08.01 |
Tag를 이용한 delegate 에서의 분기문 (0) | 2013.08.01 |
sqlLite 처리 .. (0) | 2013.07.25 |