Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7838383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T15:05:31+00:00 2026-06-02T15:05:31+00:00

Ok, I’m adding a loading screen to UITableViewController just like in the YouTube, AppStore

  • 0

Ok, I’m adding a loading screen to UITableViewController just like in the YouTube, AppStore or iTunes apps. And I’m doing it like this:

[self.view addSubview:[[LoadingView alloc] initWithFrame:self.view.bounds]];
dispatch_queue_t downloadQueue = dispatch_queue_create("downloader", NULL);
dispatch_async(downloadQueue, ^{
    //load data
    dispatch_async(dispatch_get_main_queue(), ^{
        [[self.view.subviews lastObject] removeFromSuperview]; 
        //reload data graphicaly
    });
});
dispatch_release(downloadQueue);

And LoadingView is a subclass of UIView that has a white background a spinner (UIActivityIndicatorView) and a label: “Loading…“. Now I want to place this two thing in the center and make them somewhat “rock solid”, so when you init that View on viewDidLoad and then it’s superview resizes due to the presence of navigation bar and tab bar everything stays nicely centered. Oh and I want it to handle the rotation… etc.

Now here is how I’ve tried to do it:

#define LABEL_WIDTH 80

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self setBackgroundColor:[UIColor whiteColor]];
        UIActivityIndicatorView* spinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
        UIView *innerView = [[UIView alloc] initWithFrame:CGRectMake(0,
                                                                     0,
                                                                     spinner.frame.size.width + 5 + LABEL_WIDTH,
                                                                     spinner.frame.size.height)];
        innerView.center = self.center;
        CGRect transitionFrame = spinner.frame;
        transitionFrame.origin.x = innerView.frame.origin.x;
        transitionFrame.origin.y = innerView.frame.origin.y;
        spinner.frame = transitionFrame;
        transitionFrame.origin.x = transitionFrame.origin.x+5+spinner.frame.size.width;
        transitionFrame.size.width = LABEL_WIDTH;
        UILabel *label = [[UILabel alloc] initWithFrame:transitionFrame];
        label.text = @"Loading…";
        [innerView addSubview: spinner];
        [spinner startAnimating];
        [innerView addSubview: label];
        innerView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                      UIViewAutoresizingFlexibleRightMargin |
                                      UIViewAutoresizingFlexibleTopMargin |
                                      UIViewAutoresizingFlexibleBottomMargin);
        [self addSubview:innerView];
        self.autoresizingMask = (UIViewAutoresizingFlexibleWidth|
                                 UIViewAutoresizingFlexibleHeight);
    }
    return self;
}

So the label and the spinner are set as subviews of some other view and that view is centered in our LoadingView and has all struts and springs unset, so after resizing it should stay in the middle. And LoadingView has all struts and springs set so it will change size together with it’s superview…

But it all isn’t working as intended, and I feel like I’m on the bad path and my code is wrong. Can someone help me a bit and explain what I should take a look at?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T15:05:33+00:00Added an answer on June 2, 2026 at 3:05 pm

    Seems that

    innerView.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                  UIViewAutoresizingFlexibleRightMargin |
                                  UIViewAutoresizingFlexibleTopMargin |
                                  UIViewAutoresizingFlexibleBottomMargin);
    

    was bad idea to center inner views.

    I solved it by redefining layoutSubviews method.

    The code itself can be found at https://github.com/Uko/UILoadingView/blob/master/UILoadingView.m

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.