Feb 14, 2008

Create a Dashboard in iPhone

You have seen the dashboard in iPhone UI or in Mac OS X UI. The following code snippet shows you how to create a dashboard in iPhone native application.


The code is Object C format




- (UIButtonBar *)createButtonBar

{

UIButtonBar *myButtonBar;

myButtonBar = [[UIButtonBar alloc]

initInView: self

withFrame: CGRectMake(10.0f, 380.0f, 300.0f, 100.0f)

withItemList: [self buttonBarItemList]];



[myButtonBar setDelegate: self];

// This set the style of the bar

[myButtonBar setBarStyle: 3];

// This set the tracking mode (effect when clicking on the button of the bar)

[myButtonBar setButtonBarTrackingMode: 1];



int buttons[3] = { 1, 2, 3 };

[myButtonBar registerButtonGroup: 0 withButtons: buttons withCount: 3];

[myButtonBar showButtonGroup: 0 withDuration: 0.0];



/* This set the layout of the button */

int tag;

for (tag = 1; tag < 4; tag++)

{

[[myButtonBar viewWithTag: tag]

setFrame: CGRectMake(10.0f + ((tag-1)*(80.0 + 10.0)), 1.0f, 100.0f, 80.0f)

];

}



return myButtonBar;

}


The item list of the button bar




- (NSArray *)buttonBarItemList

{

return [NSArray arrayWithObjects:

[NSDictionary dictionaryWithObjectsAndKeys:

@"buttonBarClicked:", kUIButtonBarButtonAction,

@"button_back.png", kUIButtonBarButtonInfo,

@"button_back_pressed.png", kUIButtonBarButtonSelectedInfo,

[NSNumber numberWithInt: 1], kUIButtonBarButtonTag,

self, kUIButtonBarButtonTarget,

@"Page 1", kUIButtonBarButtonType,

@"0", kUIButtonBarButtonType,

nil

],

[NSDictionary dictionaryWithObjectsAndKeys:

@"buttonBarClicked:", kUIButtonBarButtonAction,

@"button_open.png", kUIButtonBarButtonInfo,

@"button_open_pressed.png", kUIButtonBarButtonSelectedInfo,

[NSNumber numberWithInt: 2], kUIButtonBarButtonTag,

self, kUIButtonBarButtonTarget,

@"Page 2", kUIButtonBarButtonType,

@"0", kUIButtonBarButtonType,

nil

],

[NSDictionary dictionaryWithObjectsAndKeys:

@"buttonBarClicked:", kUIButtonBarButtonAction,

@"button_next.png", kUIButtonBarButtonInfo,

@"button_next_pressed.png", kUIButtonBarButtonSelectedInfo,

[NSNumber numberWithInt: 3], kUIButtonBarButtonTag,

self, kUIButtonBarButtonTarget,

@"Page 3", kUIButtonBarButtonType,

@"0", kUIButtonBarButtonType,

nil

],

nil];

}


The click message, which will handle the click event of the button bar




- (void)buttonBarClicked: (id) sender

{

}


And you will got a nice UI like this





That's all, Have fun with iPhone & Object C coding

Post a Comment