xcode - Create Menu and SubMenu's in cocoa app -
i developing cocoa app need create menu , submenu's in application.
i have attached screenshot designed using flex. how can same in cocoa.
any appreciated.
thanks.
your question incomplete,though try match solution expecting…the screenshot posted(you never mentioned source of screenshot have taken,by analysing design edited in question “flex”) looks don’t want deal nsmenuitem , nsmenu classes drop down menus…
solution 1: make custom view(probably subview of nsview popview) handles input, displaying labels,imageviews etc.
==> basically,both menu bar , menu item wrapped nsview , drop down menu wrapped nspanel…well per design have use nsview,because able add corner , yes,there possibility of adding ground colour well…the menu item has subviews of nstextview. if menu bar item has 1 text subview title, , if sub menu item has 3 text subviews, 1 check mark, 1 title , 1 hot key list…no need worry handling events,the respective classes own event handling…it’s quite complicated solution,but matches requirement…
found example you,check out code in c++.
solution 2: nstableview custom cell.could fugly, maybe worth shot.
==> create custom nstablecellview/nscell,with nsimageview(for icons pen), nstextview(for text “pen thickness”) , 1 more nsimageview(for right corner icon) it's subviews …you have perform 1 of 2 actions when user hits cell…(1) if have submenu,then again cell should create 1 more nstableview using origin (cell.frame.origin.x+cell.frame.size.width, cell.frame.origin.y)…(2) if there no submenu,perform direct task...
example: assume "menuitemcell" custom class name,in delegate method tableview willdisplaycell add cell...
- (nsview *)tableview:(nstableview *)tableview viewfortablecolumn:(nstablecolumn *)tablecolumn row:(nsinteger)row { menuitemcell *cell = [tableview makeviewwithidentifier:tablecolumn.identifier owner:self]; result.imageview.image = //ur image result.textview.setstring//; result.imageview.image = //corner image icon,if have submenu upon clicking cell. return result; }
on selecting custom cell,
- (bool)tableview:(nstableview *)tableview shouldselectrow:(nsinteger)rowindex { nslog(@"%i tapped!", rowindex); nstablecellview *selectedrow = [tableview viewatcolumn:0 row:rowindex makeifnecessary:yes]; //if have submenu,display 1 more nstableview,based on cell origin described above...don't forget add animation.. return yes; }
happy coding.. :-)
Comments
Post a Comment