我創建了一個UIButton和titleLabel。UIbutton顯示正常,titlelabel不顯示。
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 50)];
[button setBackgroundImage:[UIImage imageNamed:@"button.png"] forState:UIControlStateNormal];
button.titleLabel.text = @"Title";
button.titleLabel.font = [UIFont fontWithName:@"System-Bold" size:25.0f];
[self.view addSubview:button];
我用的版本是IOS6+
換用[button setTitle:@"Tittle" forState:UIControlStateNormal]試試,最好再設置一下字體的顏色[button setTitleColor:[UIColor redColor] forState:UIControlStateNormal]