Skip to content

Instantly share code, notes, and snippets.

@satococoa
Last active December 12, 2015 02:38
Show Gist options
  • Select an option

  • Save satococoa/4700464 to your computer and use it in GitHub Desktop.

Select an option

Save satococoa/4700464 to your computer and use it in GitHub Desktop.
ローディング中のぐるぐる機能つきの UIImageView ref: http://qiita.com/items/7ddbe9af6f323a322bf8
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
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