Abhishek Gupta
Abhishek Gupta

Reputation: 601

How to set title on UIButton

How to set text on UIButton

topYellowButton2 = [UIButton buttonWithType:UIButtonTypeCustom];
topYellowButton2.frame = CGRectMake(80, 0, 90, 20);

[topYellowButton2 setTitleColor:[UIColor colorWithRed:0.0 green:0.6 blue:1.0 alpha:1.0] forState:UIControlStateNormal];

Upvotes: 2

Views: 147

Answers (4)

QueueOverFlow
QueueOverFlow

Reputation: 1336

Simply add this line:

[topYellowButton2 setTitle:@"my button" forState:UIControlStateNormal];

Upvotes: 0

Ashutosh Dubey
Ashutosh Dubey

Reputation: 385

Set Title for both Normal and Highlighted

[topYellowButton2 setTitle:@"Button Title" forControlState:UIControlStateNormal];
[topYellowButton2 setTitle:@"Button Title" forControlState:UIControlStateHighlighted];

Upvotes: 1

Darren
Darren

Reputation: 10398

[topYellowButton2 setTitle:@"My Title" forState:UIControlStateNormal];

Upvotes: 0

Sanchit Paurush
Sanchit Paurush

Reputation: 6152

Try this

topYellowButton2=[UIButton buttonWithType:UIButtonTypeCustom]; 
topYellowButton2.frame=CGRectMake(80, 0, 90, 20);
[topYellowButton2 setTitle:@"Your Title" forState:UIControlStateNormal];

Upvotes: 2

Related Questions