0

I am new to iOS development,I was working with a UILabel. I found that the label properties are set in multiple different ways.

In the below code, it can be seen that text is assigned using the bracket notation, while textColor is assigned using dot notation. This has confused me...

[lblview setText:Cname];
lblview.textColor=[UIColor whiteColor];
lblview.font = [UIFont fontWithName:@"American Typewriter" size:18];
Wain
  • 118,658
  • 15
  • 128
  • 151
Sam
  • 571
  • 1
  • 6
  • 22

2 Answers2

0

You can use either.

lblview.textColor = [UIColor whiteColor];

is equivalent to

[lblview setTextColor:[UIColor whiteColor]];

The dot separator is just shorthand for getting/setting properties, instead of having to invoke the appropriate setter/getter method.

Janis Kirsteins
  • 2,128
  • 16
  • 17
  • So can i say lblview.setText=@"Hello" instead of [lblview setText:Cname] – Sam Feb 24 '14 at 12:36
  • no. The syntax is to either use a method call with setProperty, or dot notation without the word set, like lblview.text=@"Hello". Note that with the method call, you capitalize the first letter of the property name. – Duncan C Feb 24 '14 at 12:38
0

You can use both method for setting some value

[lblview setText:Cname];

lblview.setText = Cname;

specially set property by .(dot) method, when you made property in .h class

Gajendra Rawat
  • 3,673
  • 2
  • 19
  • 36