0

I creaded a cool Notification View, I like to make one class of it, so I just need to call [SBNotification showNotificationViewWithText:@"Test" andTextColor:[UIColor whiteColor] andNotificationBackGroundColor:[UIColor blueColor] andDelay:5 directionUp:NO]; in any ViewController.m file the problem is I don't know how to create such a class. This is my first time:)

Please help me, so I can open source this project!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
David Gölzhäuser
  • 3,525
  • 8
  • 50
  • 98

2 Answers2

0

you can get the application window in this way

UIWindow *applicationWindow = [[UIApplication sharedApplication] keyWindow];

after that you can add to the window whatever view you want and will be displayed on top of the application content

EDIT:

- (void)show {

    UIWindow *applicationWindow = [[UIApplication sharedApplication] keyWindow];

    [applicationWindow addSubView:self];
}

- (void)dismiss {

    [self removeFromSuperview];
}

off course to have something more cool you can implement animations in the 'show' and 'dismiss' method to fade ar whatever you like to do

Manu
  • 788
  • 5
  • 10
  • I think you misunderstand my question, I like to create a .h and .m file called SBNotification of Class UIWindow, I like to put in all the relevant code I need to have to display the UIWindow. so basically like a UIAlertView Class. – David Gölzhäuser Oct 27 '13 at 12:15
  • the subclass doesn't need to be a subclass of UIWindows, could be a generic subclass of UIView like UIAlertView is, and implement a method 'show' to add the view (self) to the main window and 'dismis' to remove the view (self) from the superView – Manu Oct 27 '13 at 12:18
  • I know, I can't explain it right, but i don't know how. I like to create something like this: https://github.com/scottjacksonx/SJNotificationViewController – David Gölzhäuser Oct 27 '13 at 12:22
  • see my edit... your subclass should be on UIView not UIWindow. I see that project, if it's something similar, fork it and customize in the part that you need. – Manu Oct 27 '13 at 12:26
  • I need to have a UIWindow, I can't use a UIView. – David Gölzhäuser Oct 27 '13 at 13:00
0

You can create another UIWindow in your app, but usually application is composed of one window and many views (UIView). So what you probably want is to subclass a UIView.

Take a look here:

Subclassing UIWindow

Subclassing UIView

Community
  • 1
  • 1
HyBRiD
  • 688
  • 4
  • 23