Search code examples
iosscrollpositionuilabelalert

iOS uilabel stay on screen when scrolling


In my app I was giving some information like "connection error" or "image saved" when users

caused some events. Instead of using alert view, I'd like to show labels with those text

on screen for about 2-3 secs and disappear automatically.

Most like what Android apps would do like this. (sorry for a link rather than post image due to low rep.)

As I did [superView addSubview:label] my label was attached on the back view and moved by scrolling.(superView = tableView)

How could I keep it at a fixed position of screen when user's scrolling it's superView?

prefer simple solution without using 3rd party... tho any advance would be appreciated.


Solution

  • just add a label to the superview and make it hidden

    label.hidden = YES; // write this in viewDidLoad()
    

    And in event action unhide the label

    label.hidden = NO;
    

    and then set a timer so that after 2 or 3 second the label will disapear.

    //inside event action
    [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideLabel) userInfo:nil repeats:NO];
    

    and in the selector method write code for hiding the label

     - (void) hideLabel
     {
      _lblClick.hidden = YES;  
     }
    

    I hope this is what you want......