{ explore .net }

To content | To menu | To search

Tag - iPhone

Entries feed - Comments feed

Tuesday 6 October 2009

Exploring MonoTouch with Tripy

As you might already know the people of Mono have made it possible to use the MonoDevelop IDE and C# to create applications for the iPhone. Whether this is good or bad I leave it up to you to decide, I'm just happy there is more than one way to develop for the iPhone. The thing that makes it possible is MonoTouch, the framework between the iPhone libraries and C#. MonoTouch is not free (single license costs $399, per year if you want updates) but there is a trial version to play with.

What do you need to get started:

  • Mac OS X Leopard (yes, you still need a Mac)
  • Mono framework for Mac
  • MonoTouch Framework
  • MonoDevelop for MonoTouch (it's a special version)
  • XCode and Interface Builder (should already be installed with Mac)

You can find the installation instructions and downloads on the site of MonoTouch.

Tip 1: Once you have everything installed and it's your first time using Mono on you Mac, go here to be able to launch MonoDevelop.

Tip 2: If you've never developed for the iPhone or Mac before and you know nothing of Objective-C (the natural language of Mac and iPhone) than I still suggest you to read the documentation on Apples website and maybe also read the book "Cocoa Programming for Mac OS X (3rd Edition)" (Aaron Hillegass). Trust me, this will really help you especially if you'll be using Interface Builder to create the views.

So now that you have the tools and knowledge you can get started. To help you on the way I'll be creating a sample application and publish the code on this blog as I progress but don't expect full tutorials as I don't have the time right now. The idea is to create a vacation/trip organizer and you can download the first pre-alpha release of Tripy.

The following features are included:

  • it uses a navigation controller for navigating between views
  • 3 (table)views are available (list of trips, overview of a trip, details of a trip item)
  • different examples to wire up a table view to its UITableViewDataSource and UITableViewDelegate, this also includes a custom UITableViewController
  • custom UITableViewCell created in Interface Builder
  • dummy data (no DB yet)

Future features:

  • adding, updating and deleting trips
  • more custom cells
  • SQLite support

I also try to use Interface Builder as much as possible, not only for creating the views and controls but also to wire everything up such as linking a UITableView with its UITableViewDataSource and UITableViewDelegate. In case you have no idea what I'm talking about, a UITableView uses a UITableViewDataSource to get filled and a UITableViewDelegate receives events from the UITableView.

This first code release is very rough, poorly tested and needs code cleanup/refactoring so please no comments on these subjects, this will be taken care of as I progress. If you have questions on how to do something or how something works, just drop me a comment.

You are free to use this code as you see fit but I will not take any responsibility for accidents this code might cause. The only thing I ask is to put a reference to me or this blog if you publish or change this code or applications your create with it. If you have any input, recommendations or if you want to add your own additions just let me know.

Download source code.

Wednesday 25 March 2009

Customizing controls in Interface Builder doesn't give expected result

In my previous post I talked about pimping the standard UISlider, I did the same with the UIButton and in both cases I found out that changing the images of the controls in Interface Builder doesn't give you the expected result.

For instance, to pimp the UIButton I changed the background image to a nicely shining transparent and glowing button but when I set this image in Interface Builder it still showed the standard button image behind it. If you have a non transparent image that nicely fills the UIButton you probably won't notice it but in my case it was really obvious.

When you create the button in code it appears just like you expect, no residue what so ever of the original UIButton.

If somebody has a solution or some advice on this topic please enlighten me.

UPDATE:

Fred Garvin has shown me the light.
In IB, if you use the UIButton and you want custom graphics, you need to set the "type" to "custom" (this gets rid of the other button image stuff). Then use the "Image" rather than the "Background Image" for the various assets (up, over, down states etc) by switching the drop down that defaults to "All".

Monday 23 March 2009

Pimp My UISlider

To make the interface of our application a bit more sexy we wanted to customize the standard controls of the iPhone. For instance, we designed some glassy and glowing bars to pimp the standard UISlider control.

All you need to do is create some images and write a few lines of code.

So first create your images:
- one for the thumb button
- one bar image for the left side of the thumb button, e.g. a glassy bar with an outer glow to show the "progress"
- one bar image for the right side of the thumb button, the same as the left bar but without the glow

The only thing you have to pay attention to is that both bar images have the same size. In our first test the glowing bar image was a bit bigger than the non glowing one and this caused the glow not to appear. Once we changed the right bar image to the same size everything worked perfectly.

Now you just need write some code to set the images:

CGRect rect = CGRectMake(16.0, 390.0, 297.0, 35.0);
slider.frame = rect;

UIImage* thumbImage = [UIImage imageNamed:@"thumb.png"];   
[slider setThumbImage:thumbImage forState:UIControlStateNormal];

UIImage* leftImage = [UIImage imageNamed:@"SliderLeft.png"];   
[slider setMinimumTrackImage:leftImage forState:UIControlStateNormal];   

UIImage* rightImage = [UIImage imageNamed:@"SliderRight.png"];
[slider setMaximumTrackImage:rightImage forState:UIControlStateNormal];


Just make sure that the height of the frame is big enough for your image else it gets clipped.

Friday 5 December 2008

iPhone Development

I've started some iPhone development and what an experience it is.

As other .net developers who started development on this new and exciting platform will have noticed the difference with .net is HUGE but once you get used to the development philosophy of Apple it's not that bad or difficult. The first impression you might have is that the IDE and language (objective-C) look prehistoric but you just have to accept that it's a different environment and you shouldn't compare it to Visual Studio or C# (or vb.net) and don't think about how you would solve a problem or implement a requirement in .net, you just have to change your way of thinking and adapt.

The biggest issue I had to get started was how to use the MVC pattern that you are forced to use when creating an application, how do I react to events, how do I fill the UI ... . I really grasped this concept when I read Cocoa Programming for Mac OS X (3rd Edition) . Although the book does not discuss the iPhone SDK it does give a great insight in the programming philosophy of Apple, this is a must read if you're just starting Mac or iPhone development.

So in the future I will also post about my iPhone experiences, problems, tips and tricks.....