I am creating a custom UIButton like this :
U
IButton *buttonDetailCarte = [UIButton buttonWithType:UIButtonTypeCustom];
buttonDetailCarte.frame = CGRectMake(8, 223, 304, 44);
[buttonDetailCarte setBackgroundImage:[UIImage imageNamed:@"cellule.png"] forState:UIControlStateNormal];
buttonDetailCarte.titleLabel.text = @" my Text";
buttonDetailCarte.titleLabel.font = [UIFont fontWithName:@"HelveticaNeue-Bold" size:17];
buttonDetailCarte.titleLabel.textColor = [UIColor colorWithRed:84.0/255 green:84.0/255 blue:84.0/255 alpha:1.0f];
buttonDetailCarte.backgroundColor = [UIColor clearColor];
buttonDetailCarte.titleLabel.textAlignment = UITextAlignmentLeft;
the problem that my Text don’t appear in my button and when i create the same button with IB, it appear ? what’s the problem
You should use the
setTitle:forControlState:method to change the button text, not manipulate the button’s titleLabel directly.Manipulating other properties of the
titleLabel, as you are doing, is also no recommended. Try using thesetTitleColor:instead. However, other properties likefontof the titleLabel are fine to change. It’s confusing at first but you get used to it!