Reputation: 3301
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.
Upvotes: 0
Views: 3963
Reputation: 9149
Check out a library like AJNotificationView
or JSNotifier
or HUD libraries like SVStatusHUD or MBProgressHUD
Upvotes: 2
Reputation: 6276
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:
Upvotes: 1
Reputation: 3301
Apple didn't provide any build in API's I guess to behave like toasted messages in Android.
Upvotes: 2
Reputation: 2122
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];
}
Upvotes: 2