Showing posts with label Cocoa. Show all posts
Showing posts with label Cocoa. Show all posts

Tuesday, April 28, 2015

Adding a no animation segue to iOS

If you want a view to just appear without any animation or transition in iOS then this quick tip for you. First off you do not have to code a custom segue like is suggested on several sites. All that is required is selecting the correct preset segue type and changing a simple setting. Selecting Present Modally and unchecking the Animates checkbox. That all that is needed to have the new view just appear without any animation or transition. That much easier than writing a custom segue.

If you need to see how to do this then watch this short little video;



Thanks and happy coding :)

Thursday, February 26, 2015

Swift for cocoa importing files with open panel

 Today we look at programming a open panel to import files that the user selects. Most apps do things with files so this is really a good thing to know. With swift this is pretty simple and I think you will find the example easy to do your self.




My example will show importing images that the your selected, but this same panel can open anything. From text, movies, music, folders etc.

Here the video showing how to add open files to a cocoa app using swift:



Thanks again, Happy Coding ;)

Wednesday, February 25, 2015

Swift for Mac: Programming Image Views

Today's Swift example shows how to display images “photos” in a cocoa based app. It is actually easier with Swift and Xcode, than with most third party development tools I used.

Video to watch is here:



Thanks, happy coding ;)

Monday, February 23, 2015

Swift for Mac Cocoa: Radio Buttons

When it comes to Swift for Mac OS X cocoa there very little info to be found anywhere. Google very rarely returns anything useful. The only swift examples found for the most part are for iOS not Mac. The two platforms are not really the same even if they use the same programming languages

Personally I want to use Swift for everything, because I really like it. It is possible to inter-mix Swift and Objective-C but why? Apple set up Swift to work completely on its own two feet.

Today is a basic example on how to use AppKits Radio Buttons for a Mac cocoa base app. I go over how to get which radio the user clicked on and how to set a highlighted radio cell by swift code.

I have a video showing you this in full, Here a my video on YouTube:



Thanks, happy coding ;)



Tuesday, January 27, 2015

Alert Messages with Swift

Here is a quick look at using a modal alert window with swift for Mac OS X



The main window has a simple button action to present a basic modal alert with a text string.

the code to do this in swift is:

@IBAction func btnShowAlert(sender: AnyObject)
        {
            var myAlert:NSAlert = NSAlert()
            myAlert.messageText = "Alert Text Here."
            myAlert.runModal()

    }


Alerts can be more in depth than this. This was just the basics to show how easy they are to add and use in swift. Alerts can also sheet from the main window by using;

beginSheetModalForWindow()

Instead of using the runModal()


Happy Coding;)

Saturday, January 24, 2015

Sliders with Swift

Here a quick one how to display a value of a NSSlider with swift in a field.Here the running example:


To basically only get the value from the slider we only need to make an outlet for the text field and an action for the slider. ( However if you want to set the slider by code you also need to make it an outlet also.)

The Slider action is as follows:

// field Outlet
@IBOutlet weak var fldSliderValue: NSTextField!

// NSSlider Action
@IBAction func mySlider1(sender: AnyObject) {

// x holds the value as a double as the slider changes position
var x: Double = sender.doubleValue

// to get the value to display as text string in the field do this
var mystring = x.description

// display the value in the field
fldSliderValue.stringValue = mystring

 }

Below is the source view:


Swift for Mac OS X is really fun. Will be sharing more soon.  

Tuesday, January 20, 2015

Hello Mac From Swift

After my last post about using swift to make cocoa apps on Mac OS X, I got a few questions on how to make an outlet. I guess it is easier to see it happen. Also got questions on how to do window layout constrains with Xcode for Mac also.  As I said it is easier to see this than read about it, So I show you in this video with a very simple basic Cocoa app Hello Mac again with using swift.

There a million swift examples for iOS but not to many for Mac OS X cocoa based apps, so again I keep sharing more swift for Mac stuff in the future. As I am a more a Mac OS developer more than an iOS one.

Here the video; Enjoy.

Note: (If you do not see 1080p resolution then wait for YouTube to process the higher res version. should be not to long)

 

Saturday, January 17, 2015

Using Swift for Mac OS X apps

Yesterday I ran into an issue out of my control with a 3rd party cross platform tool I use. The issue was something that may end my development with it for Mac OS X. Now I not 100% sure if I will not find a work around with that tool. However it is very clear that I need to stop putting all my eggs into one basket and make a real move into using Apple's Xcode to build for Mac OS X in the future.

I already been learning swift for iOS, however when it comes to Mac OSX there very little info or example projects floating around. Even Apple developer site has only 3 swift examples for Mac OSX but have a ton for iOS. Mac and iOS are not the same.

I decided I going to do, if my schedule allows it one or more Mac swift project a day for the next 2 months and really learn how this is done. I have already meet a dozen other developers who want to learn swift for Mac also and are trying to find examples to.

That why I going to share much of what I learn each learning project I do here as, it may help some what.

I decided to skip the Hello world app and start with working with basic text strings and very basic button actions for my first mac demo.

Now first off for a Mac swift project there only one source file the AppDelegate.swift file that all your code goes in.

You still design the interface in Interface builder much like it was done with objective c. Just like with Objective-c each object needs to be assigned an outlet or a action however this is done in the same  AppDelegate.swift file.


This example will simply take the text from each 3 fields and add it together with the process button. And secondly with the clear button remove the text from all 4 fields.

The photo below shows the outlets for all 4 text fields. to create the outlet, first put Xcode into 2 views. the left one the interface view the right one the source code view for AppDelegate.swift. (If that file does not appear in the right side of the subview. At top left corner has 4 boxes like icon, click there to get a sub menu to switch the source code for the view.) To create the outlet simple select a field while holding down the control button and drag the string like graphic to the source code view as like the photo below. This will present you with a pop over window where you name the field (such as fldFieldName) that in turn makes an outlet. do this for each field. (below is an image of the added outlets, Note the window outlet was pre made by Xcode as was the functions for app launching and will terminate) 


Next Adding actions to the buttons. This is done similar to how you create a outlet however you need to add this code after the last function Xcode made but between the last "}" symbol. Also note when the pop over appear there a pop up menu if you select that, you can change the outlet to action. That what you want to do for the button, then assign it a name and hit return.

for my mini app I have the following:
 @IBAction func btnProcessName(sender: AnyObject) {
}

Now between the {} you add your code. Working with strings in Xcode is pretty simple and is similar to many other development languages. we take the object dot property such as:

@IBAction func btnProcessName(sender: AnyObject) {
        fldFullname.stringValue
    }

To assign as value to this fields string value (text) use the = symbol and basically just add the text together. This example does not current check if a field has no text however doing such would not be hard. 

The final action that makes a full name from 3 text fields for first, middle and last name looks like this:

 @IBAction func btnProcessName(sender: AnyObject) {
        fldFullname.stringValue = fldFirstName.stringValue + " " + fldMidName.stringValue + " " + fldLastName.stringValue   
    }
And last to clear all text from the text field as simple action very similar to many programming languages. 

 @IBAction func btnClearAllText(sender: AnyObject) {
        fldFirstName.stringValue = ""
        fldMidName.stringValue = ""
        fldLastName.stringValue = ""
        fldFullname.stringValue = ""
    }
And below are additional images of this very simple swift learning example for Mac OSX.

The full source code (and yes you can make your Xcode editor any color, like mine.)

And last an screen shot of the app test running (like my input;) )


I know I did not do a video, but my upstair neighbors are very loud with there yelling and screaming that a video would not work today. If you think a video would help I could do one in the future when they calm down upstairs.

I hope this helps some as it help me making it to learn myself.

Happy coding ;) thanks for visiting.

Friday, October 3, 2014

From Livecode to Xojo buttons and such

Another look at moving from Livecode to Xojo ( two different cross platform development tools) or the other way around. This time around we look at a very basic UI elements, buttons and tab panels. One tool looks like a million bucks while the other just looks not so good.


Below image is the default button set and tab panel styles of Livecode 7.0 (with cocoa support on mac)

Below image is the default button set and tab panel styles of Xojo 2014v2 (with cocoa support on mac)


The two photos clearly show one set of controls that looks like a million bucks and another one that looks not so good. Why is this important? If you have a product aka app that does something awesome but looks bad with buggy UI no one going to want to buy it. Looks are important to so many people who are willing to pay money for something. Second one of the photo shows old outdated and even buggy controls. That will bring into question your actual app and how sound it is and if It actual works. One set of UI shows pride in ownership the other does not.

But to give it a chance beyond just photos I did a video of both Livecode and Xojo and look at the UI elements of buttons and tab panels. It may help a little choose between the two tools for your next project.



enjoy.




Monday, March 4, 2013

Mac Retina Supported Toolbars with Real Studio (Xojo)


Supporting retina base graphics in mac apps is easy. However how would one support retina graphics in an Mac Toolbar. With Retina we know we need to make all graphic files 2 times bigger than the standard resolution image. The standard resolution images files for toolbars are 32x32 pixels so high resolution needs 64x64 pixel images loaded.

Start by using toolbar icons that are 64x64 pixels and label them with an 2x suffix. Then make or use 32x32 pixel toolbar icon images for the standard resolution images. Once you have both an 2x and standard resolution icons for each toolbutton you want to add, import those into your project.

You will also need to build for Cocoa as Carbon based windows do not support high resolution displays at all.

To do this you will need to create the toolbar by code. As of the latest release 2012 r2.1 there no built in way to do this other than by code.


-

Also note that your application will also need to add the following plist setting or it will not work.

<key>NSHighResolutionCapable</key>
<true/>

If your not on an Retina based mac, you can still test your app for retina by downloading Xcode and installing the graphic add-on package. What you need is the Quartz Debugger developer tool application. Using it allows you to test for Retina based resolutions.

The code used in this video can also be used with all other image files within an retina supported app. Such as menu icons, list box icons, segmental icons and the such. Also I have examples of using pdf vector based files with segmental controls where those files alone support retina because they are using vector based images.

All the other system controls and text are fixed by simply adding the property list key:

<key>NSHighResolutionCapable</key>
<true/>

Only Images  bitmap images require the method shown in the video.

Cheers, and happy coding.

Tuesday, February 19, 2013

Retina Based Pattern Fills with Real Studio (Xojo)


Here is an look at how to do pattern fills with Real Studio that supports both standard and high resolution displays. It is really easy.


  -

Tuesday, January 22, 2013

Key Events with Class Cocoa Controls in Real Studio (Xojo)


The coolest part of using Real Studio is access to all the controls for each platform. Some of these controls are not built-in by default but are still available to use by using declares or Plugins (Like Monkey Bread Software, Complete Plugin or the Mac OSLib (free by the way.) to name an few.). Whatever you choose its up to you.

This however can present some interesting coding challenges to add support for certain events that are available to similar built in controls. Such as the text field keydown event can use an return key to preform an action. There is no keydown event however for an non built-in control, instead one needs to get creative and figure another way around this.

Lucky enough anything is possible by code. This is an simple look at getting an NSSearchField on OSX to search on clicking the Return or Enter key press. This without an event that supports keydown or keyup events.

The reason for this video is there no documentation, I could find to tell us how to do such. It was hours of trial and error to figuring it out. However I believe such information should be shared.

Here an simple video to show how this is done. I showing this off using OSX based controls, because I currently on mac. But should be similar on other platforms.


Wednesday, January 16, 2013

Mask Numbers only with text field in Cocoa

I been finding out many things that worked in Mac Carbon builds do not actually work the same in Cocoa builds. Lucky enough there are work arounds to fix many of these items.


In Carbon if we wanted to limit numbers in an text field we could simply do this in its open event. Using an mask like such:

me.text="9999"

That mask would limit numbers only and up to 4 numbers max. However masks do not work in Cocoa at all so we need to address this in an keydown event. This quick you tube video we made shows the simple and fast work around, witch does work on all platforms, Including Cocoa builds.




 I hope this helps out, moving from carbon to fully support Cocoa. As its little things like this that can make the task of converting Older Carbon apps to Cocoa not as simple as just an recompile.