Swift Sidebar on right - swift

Since i need to have the sidebar open on the right, how do i change it from the left to right side? the code i use is simple:
if revealViewController() != nil {
Menubutton.target = revealViewController()
Menubutton.action = #selector(SWRevealViewController.revealToggle(_:))
}
Also when the sidebar menu opens up it doesn't show the cells i have ( i've put both image and text on the different cells). But if i put a label in the Table view controller it shows the label when i open the sidebar menu.

To reveal from the right side, change the selector to rightRevealToggle
Menubutton.action = #selector(SWRevealViewController.rightRevealToggle(_:))

Related

How Can I change a toolbar icon in a safari app extension at runtime?

I have found this in the documentation.
https://developer.apple.com/documentation/safariservices/sfsafaritoolbaritem
which lead me to be able to use the window variable in the toolbarItemClicked function to get a reference to the toolbar item like so.
var toolbaritemretrieved = false
window.getToolbarItem { (item) in
toolbaritem = item! as SFSafariToolbarItem;
toolbaritemretrieved = true;
}
once I had a reference to the toolbar item I could then run this code and supposedly change the image of the icon.
let path = Bundle.main.path(forResource: "newIcon", ofType: "png")!;
let icon = NSImage(path);
while(!toolbaritemretrieved){
//wait for toolbar item to be retrieved
}
toolbaritem?.setImage(icon);
SFSafariApplication.setToolbarItemsNeedUpdate();
However this doesn't work. There are no visible errors but for some reason the icon does not display the new image.
Okay it turns out that there was actually nothing wrong with my code at this point and I had a forgotten breakpoint.

cocoa - what happen when close a window (by pressing the red X button)?

I'm writing an app for MacOS to display a string to a NSTextfield in a window when user click on the button in the status bar menu (application is an agent). The thing is I want to use the NSScrollView to embrace that NSTextview so that the NSTextview is scrollable. It sound simple but some thing happen:
(1) When I click the button on the menu, the window appear using the NSWindowController.showWindow(). But if the string is large (larger than the clipview), the NSScrollView isn't scrollable. If I select the text inside, then I can select the rest of the text that doesn't appear in the clipview
(2) If I leave the window there and click to the button again, then the the text is scrollable and the scrollbar appear!
(3) If I close the window by click on the red X button on top-left, then click to the button, then the window appear with the same situation at first (isn't scrollable). Notice that I don't recreate the new instance of NSWindowController of the window, at this time I just do the showWindow() with the old instance of the NSWindowController
This is the code:
if(newWC.window == nil){
let storyboard = NSStoryboard(name: "Main", bundle: nil)
newWC = storyboard?.instantiateControllerWithIdentifier("newWC") as! NewWindowController
newWC.window?.level = kCGStatusWindowLevelKey
println("new window")
}
newWC.showWindow(self)
//This is the ViewController contain the NSScrollView and the TextField
manualCopyView = newWC.window?.contentViewController as! ManualCopyViewController
var theScrollView = manualCopyView.theScrollView
var manualTextField = manualCopyView.manualEditTextField
//Calculate height of a block of string
manualTextField.stringValue = totalString.stringByAppendingString("")
var textFieldHeight = (manualTextField.cell() as! NSTextFieldCell).cellSizeForBounds(NSMakeRect(0, 0, 448, CGFloat(FLT_MAX))).height
if(textFieldHeight < 200){
textFieldHeight = 200
}
var frame = manualCopyView.manualEditTextField.frame
var clipViewFrame = theScrollView.contentView.frame
frame.size.height = textFieldHeight
//Change the frame of the textfield to fit the content string
manualTextField.frame = frame
//Gain focus to the new window
NSApp.activateIgnoringOtherApps(true)
It look like when the window first appear (or re-appear), the NSTextField is shrink even that I changed it's frame. But if I don't close it and show the window again, the frame expand as expected
I also used auto layout with constraints in the width and height of the scrollview and the width and minimum height (>= 200) of the textfield (because I think the height would be expanded)
Another question in this case: I have to set the scrollview Vertical Elasticity to No Elasticity or even the second case won't work. Is that normal?
Thank for any help.

Center Tab Bar Icons Without Text in Swift

we're trying to center the tab bar icons to the tab bar center because we don't want to have the text below. So the icons should be alone and centered in the tab bar. This is how they look now. The tab bar controller is not the root viewcontroller, so we can't access it directly using rootviewcontroller as many responses we've found out there. Any ideas? We're turning crazy...
To remove titletext, you can use code:
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil
To get center of icon tabs, use this code
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)
for complete code remove titletext and get center icon
let tabBarItems = tabBar.items! as [UITabBarItem]
tabBarItems[0].title = nil
tabBarItems[0].imageInsets = UIEdgeInsetsMake(6,0,-6,0)

Tab Bar - custom images without titles

I want to set my tab bar to have custom images but XCode insists in leaving the space for the tab bar item title text leaving my images positioned too high in the tab bar. I've tried the following code in my TabBarController.swift viewDidLoad function:
let tabItems = tabBar.items as [UITabBarItem]
tabItems[0].title = nil
tabItems[0].selectedImage = UIImage(named: "HomeWhiteIcon")
tabItems[1].title = "Database"
tabItems[1].selectedImage = UIImage(named: "Second")
tabItems[2].title = nil
tabItems[2].selectedImage = UIImage(named: "SettingsWhiteIcon")
tabItems[3].title = nil
tabItems[3].selectedImage = UIImage(named: "ReportsWhiteIcon")
However, although no title is displayed the images are positioned too high as pic below (please ignore database icon - I have not set this icon yet.
Here's a random stab as swift is not my strong suit, but perhaps the database icon having a title is causing the entire title row to not collapse. Try removing the title from the database icon.
Otherwise have you seen the setTitlePositionAdjustment method? Perhaps adjust the title's position up into the icon and the space below will go away.

OS X Application Pop Up Menu

I have a custom image button. I want to display a custom menu when clicked on it.
I am using
settingMenu.popUpMenuPositioningItem(settingMenu.itemAtIndex(0), atLocation: NSEvent.mouseLocation(), inView: nil )
I created a menu and created an outlet for it. Still I am not able to see the menu
Any Suggestions?
In AppDelegate.swift:
let statusItem = NSStatusBar.systemStatusBar().statusItemWithLength(-2)
if let button = statusItem.button {
button.image = NSImage(named: "ButtonImageHere")
button.action = Selector("actionForClickingButtonHere:")
}
func actionForClickingButtonHere(sender: AnyObject) {
//Present view, show menu list, whatever
}
If you want to hide the dock icon do this in Info.plist:
For full example see this tutorial.