Skip to content

Instantly share code, notes, and snippets.

@chrisharper22
Last active July 16, 2023 22:02
Show Gist options
  • Star 9 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save chrisharper22/17541f484f05542b0ad78a1e334835da to your computer and use it in GitHub Desktop.
Save chrisharper22/17541f484f05542b0ad78a1e334835da 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)
//
// All the important interfaces
@interface OBButtonTray : UIView
- (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
- (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];
//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