Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save nahtedetihw/f26c40e84e89c928c13e04aac3b2a4f8 to your computer and use it in GitHub Desktop.
Save nahtedetihw/f26c40e84e89c928c13e04aac3b2a4f8 to your computer and use it in GitHub Desktop.
Creating a custom OBWelcomeController in iOS 13
//
// How to use an OBWelcomeController in your project.
//
// Simalary (Chris)
// Blurred Background by Ethan Whited
// All the important interfaces
@interface OBButtonTray : UIView
@property (nonatomic,retain) UIVisualEffectView * effectView;
- (void)addButton:(id)arg1;
- (void)addCaptionText:(id)arg1;;
@end
@interface OBBoldTrayButton : UIButton
-(void)setTitle:(id)arg1 forState:(unsigned long long)arg2;
+(id)buttonWithType:(long long)arg1;
@end
@interface OBWelcomeController : UIViewController
@property (nonatomic,retain) UIView * viewIfLoaded;
@property (nonatomic,strong) UIColor * backgroundColor;
- (OBButtonTray *)buttonTray;
- (id)initWithTitle:(id)arg1 detailText:(id)arg2 icon:(id)arg3;
- (void)addBulletedListItemWithTitle:(id)arg1 description:(id)arg2 image:(id)arg3;
@end
OBWelcomeController *welcomeController; // Declaring this here outside of a method will allow the use of it later, such as dismissing.
-(void)setupWelcomeController { //This is an example method.
// Create the OBWelcomeView with a title, a desription text, and an icon if you wish. 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.
// As written here, systemImageNamed is an iOS 13 feature. It is available in the UIKitCore framework publically. You are welcome to use your own images just as usual. 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 buttonWithType:1];
[continueButton addTarget:self action:@selector(dismissWelcomeController) forControlEvents:UIControlEventTouchUpInside];
[continueButton setTitle:@"Continue" forState:UIControlStateNormal];
[continueButton setClipsToBounds:YES]; // There seems to be an internal issue with the properties, so you may need to force this to YES like so.
[continueButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; // There seems to be an internal issue with the properties, so you may need to force this to be [UIColor whiteColor] like so.
[continueButton.layer setCornerRadius:15]; // Set your button's corner radius. This can be whatever. If this doesn't work, make sure you make setClipsToBounds to YES.
[welcomeController.buttonTray addButton:continueButton];
// Set the Blur Effect Style of the Button Tray
welcomeController.buttonTray.effectView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
// Create the view that will contain the blur and set the frame to the View of welcomeController
UIVisualEffectView *effectWelcomeView = [[UIVisualEffectView alloc] initWithFrame:welcomeController.viewIfLoaded.bounds];
// Set the Blur Effect Style of the Blur View
effectWelcomeView.effect = [UIBlurEffect effectWithStyle:UIBlurEffectStyleSystemChromeMaterial];
// Insert the Blur View to the View of the welcomeController atIndex:0 to put it behind everything
[welcomeController.viewIfLoaded insertSubview:effectWelcomeView atIndex:0];
// Set the background to the View of the welcomeController to clear so the blur will show
welcomeController.viewIfLoaded.backgroundColor = [UIColor clearColor];
//The caption text goes right above the buttons, sort of like as a thank you or disclaimer. This is optional, and can be excluded from your project.
[welcomeController.buttonTray addCaptionText:@"Thank you for using this tutorial on how to use an OBWelcomeView."];
welcomeController.modalPresentationStyle = UIModalPresentationPageSheet; // The same style stock iOS uses.
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. If you don't set this, the controller will take the default color.
[self presentViewController:welcomeController animated:YES completion:nil]; // Don't forget to present it!
}
-(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