MGUAlertViewController
,MGUActionSheetController
는UIAlertController
보다 더 많은 기능과 디자인의 자유도를 보장하는 커스텀 AlertControllerUIViewControllerTransitioningDelegate
프로토콜을 따르는UIViewController
서브클래스로MGUAlertViewController
를 제작함UIPresentationController
의 커스텀 서브클래스를 이용해 프르젠테이션의 초기 설정을 관할하게함UIViewControllerAnimatedTransitioning
을 따르는 커스텀 클래스를 이용하여 present 및 dismiss를 관할하는 객체를 구성함
MGUActionSheetController
는MGUAlertViewController
의 서브클래스로 제작함
- IV-Drop을 만들면서 커스텀 AlertViewController 및 ActionSheetController의 요구사항이 있어서 제작함.
UIAlertController
과 유사한 구성 및 일반UIViewController
프리젠트와 동일한 메서드(present(_:animated:completion:)
)를 이용하여 present 및 dismissUIAlertController
과 유사한 방식으로UITextField
추가UIAlertController
과 유사한 방식으로MGUActionSheetController
는 iPad에서 프리젠트 시에 popover 스타일 지원MGUActionSheetController
는 iPad에서 백그라운드 터치로 자동 dimiss 호출됨
- 세 가지 서로 다른 커스텀 content view를 제공하여 구성 및 디자인의 자유도를 높임
- 백그라운에 대하여 Dim 스타일 또는 blur 스타일을 선택 가능
MGUAlertViewController
는 pan gesture로 dimiss 가능(On/Off 가능). 백그라운드 터치로 dimiss 가능(On/Off 가능)- 제공되는 텍스트(타이틀, 메시지, 버튼)의 font, color, 배경색 설정가능
- 다양한Transition Styles 제공 - Presets and Styles 참고
MGUAlertViewController
- Presented ViewController 에 대한 4가지 스타일 제공
- Presenting ViewController 에 대한 Scale Shrink 스타일 제공
MGUActionSheetController
- iPhone 에서 Presented ViewController 에 대한 2가지 스타일 제공
- iPad 에서 팝오버 스타일 제공
- Swift and Objective-C compatability
- Written in Objective-C
No Button | Three Buttons | TextField | Custom Font | Long Message |
---|---|---|---|---|
Custom Content View | Custom Content View | Custom Content View | IV-Drop에서 사용 | IV-Drop Onboarding |
- MGUActionSheetController
- IV-Drop을 만들면서 커스텀 ActionSheetController의 요구사항이 있어서 제작함.
- 아이패드에서는 Transition Style이 팝업 스타일로 자동 설정된다.
IV-Drop에서 사용 | IV-Drop에서 사용 | IV-Drop에서 사용 | IV-Drop에서 사용 | |
---|---|---|---|---|
아이패드에서 Preview | |
---|---|
- Transition Styles (
MGUAlertViewController
에서transitionStyle
은 iPhone, iPad 모두 동일하게 적용된다.)
- 전면부:
.fgFade
,.fgSlideFromTop
,.fgSlideFromTopRotation
,.fgSlideFromBottom
중 택 1- 후면부:
.bgScale
또는 none
.fgFade |
.fgSlideFromTop |
.fgSlideFromTopRotation |
.fgSlideFromBottom |
|
---|---|---|---|---|
.bgScale |
- Transition Styles (
MGUActionSheetController
에서transitionStyle
은 iPhone, iPad은 다르게 적용된다.)
- 아이폰:
.fgFade
,.fgSlideFromBottom
중 택 1, configuration의isFullAppearance
를true
로 설정하면 꽉찬 모양으로 표기됨.- 아이패드: 팝업 스타일로 자동 설정된다.
아이폰 | 아이패드 | ||
---|---|---|---|
Transition Style | .fgFade |
.fgSlideFromBottom |
팝업스타일로 자동 설정됨 |
Full Appearance |
Swift
let title = "타이틀"
let message = "메시지"
let configuration = MGUAlertViewConfiguration()
configuration.transitionStyle = [.fgSlideFromTop, .bgScale]
configuration.backgroundTapDismissalGestureEnabled = true
configuration.swipeDismissalGestureEnabled = true
configuration.alwaysArrangesActionButtonsVertically = false
let okActionHandler = { (action: MGUAlertAction?) -> Void in
print("Ok 버튼 눌렀음.")
}
let okAction = MGUAlertAction.init(title: "Ok", style: .default, handler: okActionHandler, configuration: nil)
let cancelActionHandler = { (action: MGUAlertAction?) -> Void in
print("Cancel 버튼 눌렀음.")
}
let cancelAction = MGUAlertAction.init(title: "Cancel", style: .cancel, handler: cancelActionHandler, configuration: nil)
let alertViewController = MGUAlertViewController(configuration: configuration, title: title, message: message, actions: [okAction, cancelAction])
present(alertViewController, animated: true)
Objective-C
NSString *title = @"타이틀";
NSString *message = @"메시지";
MGUAlertViewConfiguration *configuration = [MGUAlertViewConfiguration new];
configuration.transitionStyle = MGUAlertViewTransitionStyleFGSlideFromTop | MGUAlertViewTransitionStyleBGScale;
configuration.backgroundTapDismissalGestureEnabled = YES;
configuration.swipeDismissalGestureEnabled = YES;
configuration.alwaysArrangesActionButtonsVertically = NO;
void (^okActionHandler)(MGUAlertAction * _Nonnull) = ^(MGUAlertAction * _Nonnull action) { NSLog(@"Ok 버튼 눌렀음.");};
MGUAlertAction *okAction = [[MGUAlertAction alloc] initWithTitle:@"Ok"
style:UIAlertActionStyleDefault
handler:okActionHandler
configuration:nil];
void (^cancelActionHandler)(MGUAlertAction * _Nonnull) = ^(MGUAlertAction * _Nonnull action) { NSLog(@"Cancel 버튼 눌렀음.");};
MGUAlertAction *cancelAction = [[MGUAlertAction alloc] initWithTitle:@"Cancel"
style:UIAlertActionStyleCancel
handler:cancelActionHandler
configuration:nil];
MGUAlertViewController *alertViewController = [[MGUAlertViewController alloc] initWithConfiguration:configuration
title:title
message:message
actions:@[okAction, cancelAction]];
[self presentViewController:alertViewController animated:YES completion:nil];
-
여기에 존재하지 않는 추가적인 문서는 다음의 기술위키 문서를 참고하세요.
-
컨텐츠 배치를 위한 설계도
sonkoni(손관현), [email protected]
샘플에서 사용된 아래의 이미지의 Author는 John Alberton
This project is released under the MIT License. See LICENSE for more information.