0

過去に VB.NET を使用したことがあります。

VB.NET はオブジェクト指向言語ですが、すべてのビュー オブジェクトには名前があるため、(ButtonX) をダブルクリックすると、(ButtonX-clicked) イベントのコードを記述した場所に移動します。書いたばかりの(LabelX)の背景色を設定したい(LabelX.backgroundcolor = red)。

私は今、OS X 用のプログラムの書き方を学ぼうとしています。

ボタンをクリック"hello"してラベルに表示できるようになりましたが、そこからどこに行くべきかわかりません。

ラベル ボックスの背景色も赤に変更するボタン クリック イベントを取得するにはどうすればよいですか?

サンプルコードを提供できますか?

授業がよくわかりません。

4

2 に答える 2

0

Cocoa のイベント処理について読みたいと思うかもしれません。OS X でオブジェクト イベントを処理する方法に関する基本的な知識を提供できます。

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/EventArchitecture/EventArchitecture.html

于 2013-05-31T21:06:17.863 に答える
0

In this case the code you need is not that different in structure from what you know from VB.NET.

You say you already have the code to put "Hello" into the label, so you must have a reference to the label stored in a variable of type NSTextField *, let's say you've called this myLabel. Lookup NSTextField and you will see it has two methods backgroundColor and setBackgroundColor: - and any pair of methods following this naming pattern can be referenced as a property. So to set the background color of your label all you need is:

myLabel.backgroundColor = [NSColor redColor];

which should not look too unusual to a VB.NET person.

If you don't wish to use the property syntax you can instead write:

[myLabel setBackgroundColor:[NSColor red]];

and you will see this a lot in code as the property syntax is fairly new in Objective-C. HTH.

于 2013-05-31T21:28:37.417 に答える