Created
December 24, 2012 07:11
-
-
Save amazedkoumei/4368177 to your computer and use it in GitHub Desktop.
ブログ貼付用
This file contains 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
# -*- coding: utf-8 -*- | |
class InformView < UIView | |
attr_accessor :message | |
def init() | |
if super | |
width = 280 | |
height = 100 | |
x = (App.window.frame.size.width - width) / 2 | |
y = (App.window.frame.size.height - height) / 2 - 50 | |
self.frame = CGRectMake(x , y, width, height) | |
self.backgroundColor = UIColor.colorWithWhite(0.0, alpha:0.5) | |
self.alpha = 1.0 | |
self.layer.cornerRadius = 8.0 | |
self.layer.masksToBounds = true | |
self.clipsToBounds = true | |
@message = message | |
@label = UILabel.new.tap do |l| | |
l.frame = CGRectMake(0 , 60, 280, 30) | |
l.textColor = UIColor.whiteColor | |
l.textAlignment = NSTextAlignmentCenter | |
l.font = UIFont.boldSystemFontOfSize(18.0) | |
l.alpha = 1 | |
l.backgroundColor = UIColor.clearColor | |
self.addSubview(l) | |
end | |
@indicator = UIActivityIndicatorView.new.tap do |i| | |
i.initWithActivityIndicatorStyle(UIActivityIndicatorViewStyleWhiteLarge) | |
i.frame = CGRectMake(0 , 10, 280, 50) | |
i.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite | |
i.backgroundColor = UIColor.clearColor | |
self.addSubview(i) | |
end | |
self.hideWithAnimation(false) | |
end | |
self | |
end | |
def showWithAnimation(animated) | |
@indicator.startAnimating() | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 1.0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 1.0 | |
end | |
end | |
def hideWithAnimation(animated) | |
if animated | |
context = UIGraphicsGetCurrentContext() | |
UIView.beginAnimations(nil, context:context) | |
UIView.setAnimationDuration(0.5) | |
UIView.setAnimationDelegate(self) | |
self.alpha = 0 | |
UIView.commitAnimations() | |
else | |
self.alpha = 0 | |
end | |
@indicator.stopAnimating() | |
end | |
def drawRect(rect) | |
super | |
@label.text = @message | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment