0

Originally, I wanted to ask how to create user interfaces with cocoa programmatically, i.e. without using interface builder. But it seems that someone else has already asked this question and the answers didn't help me.

So I'll ask a different question, that I hope will indirectly help me answer the previous question. Here it is:

(QUESTION_START)

How do I create an Objective C class that is equivalent in functionality with the BoxLayout class in Java? (Just click the link, the image on that page says everything you need to know about BoxLayout.)

(QUESTION_END)

Any help in the right direction will be appreciated!

There are a few sub tasks that are connected with the question, e.g.

"How do I ask a user interface element (e.g. a button) how large it wants to be" (before it has been drawn to the screen). To draw it on the screen you have to already know its size, don't you? Obviously, the interface builder application has figured out a way to do this.

I know that many Cocoa developers think it's a stupid idea to even try what I want to do. Let me tell you: I know the reasoning behind that opinion. Right now, laying out controls without interface builder sucks, because there is nothing that comes even close to a layout manager in cocoa. But if you think my question is stupid, please DONT answer. The whole internet is full of explanations why you would never want to create UIs with code in cocoa.

Thanks!

4

1 に答える 1

0

あなたの最初の質問に答えるのはちょっと難しく、かなり複雑なので、最初にあなたのサブ質問に飛び込みます:

ユーザー インターフェイス要素 (ボタンなど) のサイズを指定するにはどうすればよいですか?

UI 要素を作成するときは、コンストラクターを介して、その大きさ (および配置場所) を指定します。initWithFrame:または、メソッドを介して後でそのフレームを設定できますsetFrame:。その後、その空間に自分自身を引き込みます。frameメソッドを介して要素のフレームを取得できます。

それを念頭に置いて、BoxLayoutクラスは、仮説的には、UI 要素を追加できるある種のコントローラーであり、BoxLayoutコントローラーはそれらを何らかのグリッド (またはその他のもの) に配置しNSViewます。

動機に疑問を投げかける答えを探していなかったのは知っていますが、BoxLayoutクラスの複雑さとIBでのインターフェースのレイアウトを考えると、なぜこれをしたいのかを尋ねることは適切だと思われます.

于 2011-06-07T20:58:50.510 に答える