0

In my app I want to show an alert like user came online.. went offline.. like that. I tried with UIAlertView, but its kind of bigger in size than what I wanted. I am new to IOS, I have explored in stack overflow also didn't got exact solution. Anyone give an idea.. what kind of notification I have to show for this case.

Need: Notification without smaller in size without ok button, should hide automatically after few seconds. (e.g.: Toast message in Android)

thanks.

Newbee
  • 3,231
  • 7
  • 42
  • 74

4 Answers4

2

Check out a library like AJNotificationView

or JSNotifier

or HUD libraries like SVStatusHUD or MBProgressHUD

Community
  • 1
  • 1
danielbeard
  • 9,120
  • 3
  • 44
  • 58
2

If you just want to show a small alert with a message, then you can do it like this:

UIAlertView *doneAlert = [[UIAlertView alloc] init];
UILabel *lblText = [[UILabel alloc] initWithFrame:CGRectMake(0, 30, 300, 22)];
lblText.text = @"User came Online\n";
lblText.font = [UIFont systemFontOfSize:15.0f];
lblText.numberOfLines = 2;
lblText.textAlignment = UITextAlignmentCenter;
lblText.backgroundColor = [UIColor clearColor];
lblText.textColor = [UIColor whiteColor];
lblText.center = CGPointMake(140, 45);
[doneAlert addSubview:lblText];
[doneAlert show];

It will show a small alert box with a message only.

Edit:

Autohide like this:

[NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(closeAlert) userInfo:nil repeats:NO];

Then method closeAlert

-(void)closeAlert {
    [doneAlert dismissWithClickedButtonIndex:0 animated:YES];
}
Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
  • Do we autohide it after few seconds? – Newbee Sep 12 '12 at 05:01
  • 1
    Yes, after this code I set a timer for 1 second, which fires a method and that method dismisses the alert, so you'll have to take the alert object global. – Kanan Vora Sep 12 '12 at 05:03
  • One more question-When we use UIAlertview background is going dark like inactive and focus will come to UIAlertview.. in real time many people will go online, offline, frequent showing will not look good I think, any idea? – Newbee Sep 12 '12 at 05:07
  • That's true, it is not feasible to show pop up like this every time any user comes online or goes offline, for that you can just add a button for each user, in the list. Beside the name of the user, if user comes online, change the button color to green, or else keep some other color. Or you can use anything in place of button. – Kanan Vora Sep 12 '12 at 05:10
  • Can you please correct my answer, if it was a true solution to your problem, so that it can be useful for others too. thanks... – Kanan Vora Sep 12 '12 at 05:13
  • Ya I'm already doing this in Address book, apart from this I need user should come to know by alert. – Newbee Sep 12 '12 at 05:22
2

Apple didn't provide any build in API's I guess to behave like toasted messages in Android.

Newbee
  • 3,231
  • 7
  • 42
  • 74
1

You could try out ALAlertBanner. It's a project I just finished. It has tap to dismiss, auto-hide, and a couple other nice features.

Here's a screenshot:

ALAlertBanner

lobianco
  • 6,226
  • 2
  • 33
  • 48