UIButton text is not displayed

advertisements

I have a UIButton on table cell. I am trying to set its text but it is not displaying it.

UIButton *btnName = [[UIButton alloc]init];
btnName.frame = CGRectMake(0.0, imgPic.frame.origin.y+imgPic.frame.size.height+10.0, self.frame.size.width, 20.0);
btnName.center = CGPointMake(cell.contentView.center.x, imgPic.frame.origin.y+imgPic.frame.size.height+10.0);
btnName.titleLabel.text = [@"Nitin" uppercaseString];
//[btnName setTitle:[@"Nitin" uppercaseString] forState:UIControlStateNormal];
[cell.contentView addSubview:btnName];


Found the solution :

UIButton *btnName = [UIButton buttonWithType:UIButtonTypeRoundedRect];

also use

[btnName setTitle:[@"Nitin" uppercaseString] forState:UIControlStateNormal];

instead.

Please see Christien's answer.