Monday 4 June 2012

Create Custom Button with multiple line....

UILabel
Allow you to setup max. no. of line

UIButton
Button’s size varies with length of title. Button can’t support multiple lines and linebreak. Using background image or frame won’t support multiple lines. It’s possible to addSubview a UILabel to the button.
UIButton *button;
// Set UIbutton type
button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
// Set UIbutton background image for Normal state
[button setBackgroundImage:img forState:UIControlStateNormal];
// Set UIButton background image for Highlighted state
[button setBackgroundImage:buttonBackgroundPressed forStates:UIControlStateHighlighted];
// Set UIButton title for Normal, Highlighted, Selected States
[button setTitle:@"Normal State" forState:UIControlStateNormal];
[button setTitle:@"Highlighted State" forState:UIControlStateHighlighted];
[button setTitle:@"Selected State" forState:UIControlStateSelected];
// Set UIButton font
button.font = [UIFont boldSystemFontOfSize:BUTTON_FONT_SIZE];
// Set UIButton horizontal and vertical alignment
button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
button.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
// Assign method to UIButton action and control event
[button addTarget:self action:@selector(buttonMethod) forControlEvents:UIControlEventTouchUpInside];
// set UIButton to center
button.center = CGPointMake( 45.0, 240.0);
// set UIButton background color
button.backgroundColor = [UIColor clearColor];
// addSubview to UIButton
[ContentView addSubview:oneButton];
// release UIButton memory

[button release];

No comments:

Post a Comment