{"id":156,"date":"2012-03-24T06:08:18","date_gmt":"2012-03-24T06:08:18","guid":{"rendered":"http:\/\/ootips.org\/yonat\/?p=156"},"modified":"2016-04-17T07:18:33","modified_gmt":"2016-04-17T07:18:33","slug":"simple-uiprogresshud-replacement","status":"publish","type":"post","link":"https:\/\/ootips.org\/yonat\/simple-uiprogresshud-replacement\/","title":{"rendered":"Simple UIProgressHUD replacement"},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2012\/03\/ActivityHUD.png\" alt=\"\" title=\"ActivityHUD\" width=\"85\" height=\"83\" class=\"alignleft size-full wp-image-157\" \/><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2012\/03\/ActivityHUDScreen.png\" alt=\"\" title=\"ActivityHUDScreen\" width=\"198\" height=\"372\" class=\"alignright size-full wp-image-158\" srcset=\"https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2012\/03\/ActivityHUDScreen.png 198w, https:\/\/ootips.org\/yonat\/wp-content\/uploads\/2012\/03\/ActivityHUDScreen-159x300.png 159w\" sizes=\"auto, (max-width: 198px) 100vw, 198px\" \/>The private API <a href=\"http:\/\/www.cocoadev.com\/index.pl?UIProgressHUD\" target=\"_blank\">UIProgressHUD<\/a> shows an activity indicator (spinner) over a shaded round rect. Although you can use fancy and flexible replacements like <a href=\"http:\/\/github.com\/matej\/MBProgressHUD\" target=\"_blank\">MBProgressHUD<\/a>, there is a simpler way if you don&#8217;t need all the extra functionality: Take a regular <b>UIActivityIndicatorView<\/b> and add a partly transparent UIView behind it.<\/p>\n<p>The simplest is to subclass of UIActivityIndicatorView so you can use it like any activity indicator.<\/p>\n<p>The interface file:<\/p>\n<pre class=\"lang:objc decode:true \">\r\n\/\/  ActivityHUD.h\r\n#import <UIKit\/UIKit.h>\r\n\r\n@interface ActivityHUD : UIActivityIndicatorView\r\n- (ActivityHUD *)initInView:(UIView *)view;\r\n@end\r\n<\/pre>\n<p>And the implementation file:<\/p>\n<pre class=\"lang:objc decode:true \">\r\n\/\/  ActivityHUD.m\r\n#import \"ActivityHUD.h\"\r\n#import <QuartzCore\/QuartzCore.h>\r\n\r\n@implementation ActivityHUD\r\n\r\n- (ActivityHUD *)initInView:(UIView *)view\r\n{\r\n    self = [super initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];\r\n    if (self) {\r\n        \/\/ add background view\r\n        CGFloat border = self.bounds.size.height \/ 2;\r\n        CGRect hudFrame = CGRectInset(self.bounds, -border, -border);\r\n        UIView *hud = [[UIView alloc] initWithFrame:hudFrame];\r\n        hud.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.67];\r\n        hud.layer.cornerRadius = border;\r\n        [self addSubview:hud];\r\n        [self sendSubviewToBack:hud];\r\n\r\n        \/\/ center in parent view\r\n        [view addSubview:self];\r\n        self.center = [self convertPoint:view.center fromView:view];\r\n    }\r\n    return self;\r\n}\r\n\r\n@end\r\n<\/pre>\n<p>To use, init the <tt>ActivityHUD<\/tt> in a view, and later call <tt>startAnimating<\/tt> to show it, and <tt>stopAnimating<\/tt> to hide.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The private API UIProgressHUD shows an activity indicator (spinner) over a shaded round rect. Although you can use fancy and flexible replacements like MBProgressHUD, there is a simpler way if you don&#8217;t need all the extra functionality: Take a regular &hellip; <a href=\"https:\/\/ootips.org\/yonat\/simple-uiprogresshud-replacement\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","enabled":false},"version":2}},"categories":[1],"tags":[18,7,6,13,14],"class_list":["post-156","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-cocoa","tag-ios","tag-iphone","tag-objective-c","tag-sample-code"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2aEUP-2w","_links":{"self":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/156","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/comments?post=156"}],"version-history":[{"count":8,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/156\/revisions"}],"predecessor-version":[{"id":246,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/posts\/156\/revisions\/246"}],"wp:attachment":[{"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/media?parent=156"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/categories?post=156"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ootips.org\/yonat\/wp-json\/wp\/v2\/tags?post=156"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}