[英]How to make the NSButton above a NSButton?
我有兩個NSButton。 兩個按鈕都帶有圖像。 這就是我創建的[buttons]( http://i.stack.imgur.com/IYXIE.png )問題是星型按鈕始終位於葉子按鈕的后面。 我怎么能把它放在前面。 (搜索Mac osx而不是iOS。)
更新:這是我第一次鼠標懸停時得到的 ,在第二次滑過鼠標時得到了
[starButton removeFromSuperview];
[self addSubview:starButton positioned:NSWindowAbove relativeTo:nil];
另外,NSView支持該方法
sortSubviewsUsingFunction:context:
實現只對視圖排序的方法..需要更多代碼,但看起來更干凈。
您可以使用BringSubviewToFront強制一個視圖出現在另一個視圖的“頂部”:
[parentView bringSubviewToFront:view];
如果要在情節提要設計器中更改視圖的順序,只需將所需的視圖拖到左側菜單中另一個視圖下方的頂部即可。 最頂部的視圖始終是列表中最后顯示的視圖。
我使用A
代替星號,使用Apple
代替Leave。
您正在這樣做:
您需要將按鈕位置更改為:
將按鈕A
放在Apple
后面 。
然后您將根據您的要求進行查看。
這會做
[parentView bringSubviewToFront:leafButton];
[parentView bringSubviewToFront:starButton];
要將子視圖置於macOS的最前面,請執行以下操作:
NSView *superView = myObject.superview;
[myObject removeFromSuperview];
[superView addSubview:myObject]; // brings to the front
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.