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 7991119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:12:17+00:00 2026-06-04T13:12:17+00:00

I am wrapping my head around using categories for some things where I might

  • 0

I am wrapping my head around using categories for some things where I might previously have been using inheritance.

The thing I am doing now is more of a best-practice question where I am not sure how it should be implemented. I am writing a category on UIActivityIndicatorView which basically will be used to put a activity indicator in an arbitrary view. Below you’ll find the code example of how I am doing it and my main question is whether or not this is good. And I would appreciate comments on why it’s bad if that is the case. Thanks.

The category:

@interface UIActivityIndicatorView (Customizations)
    - (UIActivityIndicatorView *) inView:(UIView *) target;
@end

Implementation:

@implementation UIActivityIndicatorView (Customizations)

- (UIActivityIndicatorView *) inView:(UIView *) target {
    [self startAnimating];
    [self setHidden:NO];
    self.frame = target.bounds;
    self.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.6f];

    return self;
}
@end

Then I would use it like this:

[background addSubview:[loader inView:background]];

I am guessing that another way of doing it would be to make an initialization function to take the container view and just return the “styled” view, or perhaps not return anything (void) and just let the method do the styling.

So I am looking for some guidance as to how to handle this.

  • 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-04T13:12:19+00:00Added an answer on June 4, 2026 at 1:12 pm

    What kind of worries me is that I am actually making a second copy of the UIActivityIndicatorView which seem unnecessary

    No, you don’t. You might be confused by the fact that you are returning self from your category method, but that is just a pointer, not the object itself getting copied.

    However, I would implement it slightly different:

    - (void) addToSuperView:(UIView *) target {
        [self startAnimating];
        [self setHidden:NO];
        self.frame = target.bounds;
        self.backgroundColor = [UIColor colorWithRed:0.0f green:0.0f blue:0.0f alpha:0.6f];
    
        [target addSubview:self];
    }
    

    That way, you don’t need to make an extra, unnecessary call when adding it:

    [loader addToSuperView:background];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having trouble wrapping my head around how to do this. I have a
Am wrapping my head around JavaScript closures and am at a point where things
I'm having problems wrapping my head around this. I have a function void foo(istream&
I'm having a rough time wrapping my head around this. I have an HTML
Been wrapping my head around this problem for a while and looking for solutions
I'm having trouble wrapping my head around joining tables. I have a one_to_many relationship
I'm having some troubles wrapping my head around how to go about parsing some
Having a hard time wrapping my head around this one. I have a Page
I'm having trouble wrapping my head around a query. I have the following 3
I'm looking for some help wrapping my head around a good approach/architecture to handle

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.