Created
March 1, 2009 17:53
-
-
Save takuma104/72414 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
# basic test ;) | |
irb(main):001:0> 1+2 | |
3 | |
# I want to get MyAppDegetate instance | |
irb(main):002:0> OSX::UIApplication | |
OSX::UIApplication | |
irb(main):003:0> OSX::UIApplication.sharedApplication | |
#<OSX::UIApplication:0x1eefba class='UIApplication' id=0x26f6d0> | |
irb(main):004:0> OSX::UIApplication.sharedApplication.delegate | |
#<MyAppDelegate:0x1f8e70 class='MyAppDelegate' id=0x29dea0> | |
# done! | |
irb(main):005:0> app = OSX::UIApplication.sharedApplication.delegate | |
#<MyAppDelegate:0x1f8e70 class='MyAppDelegate' id=0x29dea0> | |
# UIWindow instance | |
irb(main):006:0> app.window | |
#<OSX::UIWindow:0x1f8c40 class='UIWindow' id=0x2c0080> | |
# UILabel instance | |
irb(main):008:0> app.textView | |
#<OSX::UILabel:0x1f8902 class='UILabel' id=0x2e2e00> | |
# making the window color white | |
irb(main):009:0> app.window.setBackgroundColor OSX::UIColor.whiteColor | |
nil | |
# oh, the label disapeared. making the label color black | |
irb(main):012:0> app.textView.setTextColor OSX::UIColor.blackColor | |
nil | |
# I'd like to show on the window a image from web | |
irb(main):013:0> gif = open('http://www.ruby-lang.org/images/logo.gif','rb') {|f| f.read } | |
Errno::ENOENT: No such file or directory - http://www.ruby-lang.org/images/logo.gif | |
from (irb):13:in 'initialize' | |
from (irb):13:in 'open' | |
from (irb):13 | |
# oops, we need open-uri | |
irb(main):014:0> require 'open-uri' | |
true | |
# done | |
irb(main):015:0> gif = open('http://www.ruby-lang.org/images/logo.gif','rb') {|f| f.read } | |
"GIF89a...." | |
# creating UIImage | |
irb(main):016:0> img = OSX::UIImage.imageWithData(OSX::NSData.dataWithBytes_length(gif, gif.length)) | |
NameError: uninitialized constant OSX::UIImage | |
from (irb):16 | |
# oops, we need OSX::ns_import (please try when you get NameError) | |
irb(main):017:0> OSX::ns_import :UIImage | |
OSX::UIImage | |
# ooops, NSData too. | |
irb(main):018:0> img = OSX::UIImage.imageWithData(OSX::NSData.dataWithBytes_length(gif, gif.length)) | |
NameError: uninitialized constant OSX::NSData | |
from (irb):18 | |
irb(main):019:0> OSX::ns_import :NSData | |
OSX::NSData | |
# UIImage created | |
irb(main):020:0> img = OSX::UIImage.imageWithData(OSX::NSData.dataWithBytes_length(gif, gif.length)) | |
#<OSX::UIImage:0x1e23f0 class='UIImage' id=0x287850> | |
# creating UIImageView | |
irb(main):021:0> imgview = OSX::UIImageView.alloc.initWithImage img | |
NameError: uninitialized constant OSX::UIImageView | |
from (irb):21 | |
# oops | |
irb(main):022:0> OSX::ns_import :UIImageView | |
OSX::UIImageView | |
# UIImageView created | |
irb(main):023:0> imgview = OSX::UIImageView.alloc.initWithImage img | |
#<OSX::UIImageView:0x1d1af0 class='UIImageView' id=0x31c48d0> | |
# try addSubview | |
irb(main):026:0> app.window.addSubview imgview | |
nil | |
# tweaking、ImageView frame | |
irb(main):028:0> imgview.frame | |
#<OSX::CGRect:0x376dec @size=#<OSX::CGSize:0x376ba8 @height=119.0, @width=331.0>, | |
@origin=#<OSX::CGPoint:0x376d38 @y=0.0, @x=0.0>> | |
irb(main):030:0> imgview.setFrame [-5,140] + imgview.frame.size.to_a | |
nil | |
# tweaking textView(Label) frame | |
irb(main):034:0> app.textView.setFrame [0,260,320,40] | |
nil | |
# tweaking label text | |
irb(main):035:0> app.textView.setText 'with RubyCocoa' | |
nil | |
# use more large font | |
irb(main):042:0> app.textView.setFont OSX::UIFont.boldSystemFontOfSize(32) | |
nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment