Forked from chrisharper22/OBWelcomeControllerExample.m
Last active
May 1, 2021 12:55
-
-
Save aydenp/0cedb5a3a113ff9751666255bd5aa120 to your computer and use it in GitHub Desktop.
Creating a custom OBWelcomeController in iOS 13
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// How to use an OBWelcomeController in your project. | |
// | |
// Simalary (Chris) | |
// | |
// All the important interfaces | |
@interface OBButtonTray : UIView | |
- (void)addButton:(UIButton *)button; | |
- (void)addCaptionText:(NSString *)captionText; | |
@end | |
@interface OBBoldTrayButton : UIButton | |
+ (instancetype)boldButton; | |
@end | |
@interface OBWelcomeController : UIViewController | |
- (OBButtonTray *)buttonTray; | |
- (instancetype)initWithTitle:(NSString *)title detailText:(NSString *)detailText icon:(UIImage *)icon; | |
- (void)addBulletedListItemWithTitle:(NSString *)title description:(NSString *)description image:(UIImage *)image; | |
@end | |
OBWelcomeController *welcomeController; // Declaring this here outside of a method will allow the use of it later, such as dismissing. | |
- (void)setupWelcomeController { | |
// Create the OBWelcomeViewController. Any of this can be nil if it doesn't apply to your view. | |
welcomeController = [[OBWelcomeController alloc] initWithTitle:@"OBWelcomeController Example" detailText:@"This is some text to welcome you. Please take off your shoes before entering." icon:[UIImage systemImageNamed:@"gear"]]; | |
// Create a bulleted item with a title, description, and icon. Any of the parameters can be set to nil if you wish. You can have as little or as many of these as you wish. The view automatically compensates for adjustments. | |
// systemImageNamed refers to an SF Symbol by name. It is public. You are welcome to use your own images too - make sure you set them up with UIImageRenderingModeAlwaysTemplate to allow proper coloring. | |
[welcomeController addBulletedListItemWithTitle:@"Point One" description:@"Something important may go here, or it may not even be important. Who cares, amirite?" image:[UIImage systemImageNamed:@"1.circle.fill"]]; | |
[welcomeController addBulletedListItemWithTitle:@"Point Two" description:@"It's a bird! Wait, no! It's a plane! Haha, just kidding, it's an OBWelcomeController." image:[UIImage systemImageNamed:@"2.circle.fill"]]; | |
[welcomeController addBulletedListItemWithTitle:@"Point Three" description:@"Do people even read these? Like, people don't read the Terms & Conditions, so why would this be any different?" image:[UIImage systemImageNamed:@"3.circle.fill"]]; | |
// Create your button here, set some properties, and add it to the controller. | |
OBBoldTrayButton* continueButton = [OBBoldTrayButton boldButton]; | |
[continueButton addTarget:self action:@selector(dismissWelcomeController) forControlEvents:UIControlEventTouchUpInside]; | |
[continueButton setTitle:@"Continue" forState:UIControlStateNormal]; | |
[welcomeController.buttonTray addButton:continueButton]; | |
// Caption text goes above the buttons. Apple uses this for legal-ish text, you might for a thank you or disclaimer. This is optional. | |
[welcomeController.buttonTray addCaptionText:@"Thank you for using this tutorial on how to use an OBWelcomeView."]; | |
welcomeController.modalPresentationStyle = UIModalPresentationPageSheet; // Present within a swipable sheet, like most welcome screens in stock iOS. | |
welcomeController.modalInPresentation = YES; // Set this to yes if you don't want the user to dismiss this on a down swipe. | |
welcomeController.view.tintColor = [UIColor systemGreenColor]; // If you want a different tint color. | |
[self presentViewController:welcomeController animated:YES completion:nil]; | |
} | |
- (void)dismissWelcomeController { // Say goodbye to your controller. :( | |
[welcomeController dismissViewControllerAnimated:YES completion:nil]; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment