除非单击,否则不会显示 UIButton 标题



除了问题的标题之外,我不知道如何描述问题:我有一个带有标题的按钮,单击时会出现标题,但不处于正常状态。我到处环顾四周,但无济于事。

如果您需要查看特定代码或想要其他详细信息(我相信您会这样做),请告诉我。

编辑:按钮是在笔尖中创建的,但这里是设置标题的代码,还处理按钮的子视图。

[chapterButton setTitle:[NSString stringWithFormat:@"%@: %d",newBookName,newChapter] forState:UIControlStateNormal];
UIImageView *triunghiView = (UIImageView *) [chapterButton viewWithTag:kTagTriangleView];
if(!triunghiView)
{
    triunghiView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"triunghi.png"]] autorelease];
    [triunghiView setContentMode:UIViewContentModeCenter];
    [triunghiView setTag:kTagTriangleView];
    [triunghiView sizeToFit];
    [chapterButton addSubview:triunghiView];
}
[triunghiView setCenter:CGPointMake(chapterButton.titleLabel.frame.origin.x + chapterButton.titleLabel.frame.size.width + triunghiView.frame.size.width + 5, chapterButton.frame.size.height/2)];

我最近遇到了这个问题,您还必须设置按钮的标题颜色,否则它会变白并显得不可见(在圆形矩形按钮的默认设置中)。

[btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

然而,这也可能是Kjuly的答案! 没有代码,很难分辨。

没有代码,好吧,猜你可能为你的标题设置了一个错误的状态。

[yourButton setTitle:@"Title" forState:UIControlStateNormal];

最新更新