views:

20

answers:

3

Friends,

I am a beginner and trying to know iphone programming basics. If I create a Label from Interface Builder and Name it as "Sample", can I change the font of this Label name from source code. Is it possible. I have no clue how to do it. Can anyone help me in doing this.

Thanks In Advance, Anil

+1  A: 

simply create an IBOutlet for Sample, connect it up in IB and then you can access any Label instance and class methods directly in your code. The IBOutlet should look like this this in your header file:

In the interface definition declare a UILabel:

UILabel *sample;

create a property by including the following in your header and implementation files respectively:

@property (nonatomic, retain) IBOutlet UILabel *sample;
@synthesize sample;
ennuikiller
And then, use sample.font = ....; ;-)
Eiko
Thanks ennuikiller,I tried the same as u said but there is no effect. Below is what i did :I declared in .h file UILabel *sample;in .m@property (nonatomic, retain) IBOutlet UILabel *sample;@synthesize sample;sample.font = [UIFont systemFontOfSize:10.0];In Interface Builder I have connected sample to Sample by dragging from File Owner. Now when I run the code I see no variation to the font size of "Sample"
Anil Kumar
oh i messed it I again paste it as Answer to look better
Anil Kumar
A: 

Below is what i did :

I declared in .h file

   UILabel *sample; 

and in .m

   @property (nonatomic, retain)

   IBOutlet UILabel *sample;

   @synthesize sample;

   sample.font = [UIFont systemFontOfSize:10.0]; 

In Interface Builder I have connected sample to Sample by dragging from File Owner. Now when I run the code I see no variation to the font size of "Sample"

Anil Kumar
+1  A: 

Where in your code you are changing the font? If you change that in init method then it won't have any effect. The reason is IBOutlet connections are yet to be build. You can do it in viewDidLoad method.

- (void)viewDidLoad {
   self.sample.font = [UIFont systemFontOfSize:10.0];  
}
taskinoor
Thanks taskinoor, its working
Anil Kumar