forked from HipByte/RubyMotionSamples
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Timer.app | ||
|
||
This sample demonstrates the following concepts: Timer, Label, Button. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
$:.unshift("/Library/Motion/lib") | ||
require 'motion/project' | ||
|
||
Motion::Project::App.setup do |app| | ||
# Use `rake config' to see complete project settings. | ||
app.name = 'Timer' | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class AppDelegate | ||
def application(application, didFinishLaunchingWithOptions:launchOptions) | ||
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds) | ||
@window.rootViewController = TimerController.alloc.init | ||
@window.rootViewController.wantsFullScreenLayout = true | ||
@window.makeKeyAndVisible | ||
true | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
class TimerController < UIViewController | ||
def viewDidLoad | ||
margin = 20 | ||
|
||
@state = UILabel.new | ||
@state.font = UIFont.systemFontOfSize(30) | ||
@state.text = 'Tap to start' | ||
@state.textAlignment = UITextAlignmentCenter | ||
@state.textColor = UIColor.whiteColor | ||
@state.backgroundColor = UIColor.clearColor | ||
@state.frame = [[margin, 200], [view.frame.size.width - margin * 2, 40]] | ||
view.addSubview(@state) | ||
|
||
@action = UIButton.buttonWithType(UIButtonTypeRoundedRect) | ||
@action.setTitle('Start', forState:UIControlStateNormal) | ||
@action.setTitle('Stop', forState:UIControlStateSelected) | ||
@action.addTarget(self, action:'actionTapped', forControlEvents:UIControlEventTouchUpInside) | ||
@action.frame = [[margin, 260], [view.frame.size.width - margin * 2, 40]] | ||
view.addSubview(@action) | ||
end | ||
|
||
def actionTapped | ||
if @timer | ||
@timer.invalidate | ||
@timer = nil | ||
else | ||
@duration = 0 | ||
@timer = NSTimer.scheduledTimerWithTimeInterval(0.1, target:self, selector:'timerFired', userInfo:nil, repeats:true) | ||
end | ||
@action.selected = !@action.selected? | ||
end | ||
|
||
def timerFired | ||
@state.text = "%.1f" % (@duration += 0.1) | ||
end | ||
end |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
describe "Application 'Timer'" do | ||
before do | ||
@app = UIApplication.sharedApplication | ||
end | ||
|
||
it "has one window" do | ||
@app.windows.size.should == 1 | ||
end | ||
end |