In the previous tutorial, we saw how to make an action for a button to write text in a label.
In this tutorial, we will strengthen this aqcuis. Indeed, the previous code will add the necessary code to change the font and Colour of the text of a label.
So, let's starting .
Download Source Code
1)Add in .h file this Code :
UIButton *btnColor;
//.....
@property (nonatomic,retain)IBOutlet UIButton *btnColor;
//.....
- (IBAction)buttonPressedB:(id)sender;
So the full Code of this file become :
#import <UIKit/UIKit.h>
@interface demo2AddButtonViewController : UIViewController {
UILabel *mylabel;
UIButton *myButton;
UIButton *btnColor;
}
@property (nonatomic,retain)IBOutlet UILabel *myLabel;
@property (nonatomic,retain)IBOutlet UIButton *myButton;
@property (nonatomic,retain)IBOutlet UIButton *btnColor;
- (IBAction)buttonPressed:(id)sender;
- (IBAction)buttonPressedB:(id)sender;
@end
=>Indeed, the addition of this code is used to define another button and also to define its action
2)Add this Code in the .m file :
@synthesize btnColor;
//.....
- (IBAction)buttonPressedB:(id)sender
{
[myLabel setTextColor:[UIColor redColor]];
[myLabel setFont:[UIFont boldSystemFontOfSize:33]];
}
The Full Code OF .m file :
#import "demo2AddButtonViewController.h"
@implementation demo2AddButtonViewController
@synthesize myLabel;
@synthesize myButton;
@synthesize btnColor;
- (IBAction)buttonPressed:(id)sender
{
[myLabel setText:@"Peace Up To You"];
}
- (IBAction)buttonPressedB:(id)sender
{
[myLabel setTextColor:[UIColor redColor]];
[myLabel setFont:[UIFont boldSystemFontOfSize:33]];
}
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc {
[super dealloc];
}
@end
===
Don't forget to link your Action To its method( buttonPressedB).
Choose
As yo see, It's the same principle as the first tuto,But this tutorial lets you practice using , advancing well.
Before Click on btnColor :
After Clicking:
No comments:
Post a Comment