Last active
December 12, 2015 02:38
-
-
Save satococoa/4700464 to your computer and use it in GitHub Desktop.
ローディング中のぐるぐる機能つきの UIImageView ref: http://qiita.com/items/7ddbe9af6f323a322bf8
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class LoadableImageView < UIImageView | |
| attr_accessor :loading, :loading_view | |
| def initWithFrame(rect) | |
| super | |
| @loading = false | |
| @loading_view = UIActivityIndicatorView.alloc.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhite).tap do |lv| | |
| lv.color = UIColor.blackColor | |
| end | |
| self | |
| end | |
| def loading=(loading) | |
| if loading | |
| self.image = nil | |
| addSubview(@loading_view) | |
| @loading_view.startAnimating | |
| else | |
| @loading_view.stopAnimating | |
| end | |
| end | |
| def layoutSubviews | |
| super | |
| w = 30 | |
| h = 30 | |
| x = (self.frame.size.width/2.0 - w/2) | |
| y = (self.frame.size.height/2.0 - h/2) | |
| @loading_view.frame = [[x, y], [w, h]] | |
| end | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| image_view = LoadableImageView.new | |
| # ぐるぐる出す | |
| image_view.loading = true | |
| # ぐるぐるやめる | |
| image_view.loading = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment