bloemy bloemy - 1 year ago 73
Objective-C Question

iOS - Globally change MBProgressHUD design

I use MBProgressHUD for loading screens in my app. I have 26 occurrences where I use a different HUD.

Now, I've decided to use a customised UIView (an animated UIImageView) for the HUD. I want to apply this to all the HUD's I use in my app, but the code to customise the HUD is about 15 lines long, and it's definitely not the right method to add this code to every single occurrence of a MBProgressHUD in my app.

What's the right way to go from here? This is not the first time I've run into an issue like this where I'm not sure how to keep my code cleaner and simpler.

Answer Source

One way is to declare the spinner in the AppDelegate, and write the methods showSpinner and hideSpinner, and also define a macro to call these spinner methods.

And you can just use this macro globally in your project.It is also easy to change the spinner code in the app delegate and you don't have to change anything.