【问题标题】:UIImage view picture title in uibuttonUIImage在uibutton中查看图片标题
【发布时间】:2012-10-29 07:30:31
【问题描述】:

在我的应用程序中,我有 1 个图像视图和 4 个按钮,我想在其中一个按钮标题中显示图像名称,其余 3 个按钮应显示其他标题,这是我的代码,它不起作用,请帮助我来解决

-(IBAction)answersetting:(id)sender
{
UIButton *mybutton = (UIButton *)sender;
static int j = 0;
if(sender == mybutton)
    j++;
if (j >= arcount)
{
    j = 0;
}
else if(j < 0)
{
    j = arcount - 1;
}
animage.image=[arimage objectAtIndex:j];
for(UIView *view in self.view.subviews)
{
    if([view isKindOfClass:[UIButton class]])
    {
        UIButton *button = (UIButton *)view;
        if(button.tag == 1||button.tag == 2||button.tag == 3||button.tag == 4)
        {
            int value = rand() % ([artext count] -1) ;
            NSMutableDictionary *dictionary = [[NSMutableDictionary alloc]init];
            [dictionary setValue:@"imageName" forKey:@"button"];
            [button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];

        }
    }
}

}

【问题讨论】:

  • UIButton *mybutton = (UIButton *)sender; ..if(sender == mybutton) 我觉得这个if语句没用。
  • @KevinCao 我用它在点击时显示下一张图片
  • @fasilmoham:你能把你的问题说得更清楚吗?
  • 在我看来,我有 1 个图像视图和 4 个按钮,我在图像视图中从数组中显示图像,因为我想将 1 个按钮标题显示为当前图像名称,其余按钮作为不同名称数组。我无法在按钮标题中显示图像当前图像名称,你能帮我解决@VenkatManohar
  • @fasilmoham:按钮标题应该是什么......就像你在其他地方保存图像名称一样?

标签: iphone ios uiimageview uibutton


【解决方案1】:

代替:

[button setTitle:[artext objectAtIndex:value] forState:UIControlStateNormal];

试试这个:

[button setTitle:[NSString stringWithFormat:@"%@",[artext objectAtIndex:value]] forState:UIControlStateNormal];

还要确保[artext objectAtIndex:value] 确实包含一些值。

【讨论】:

  • 太棒了,它的工作问题是它像这样&lt;UIImage: 0x7577460&gt;,我怎样才能得到准确的单词
猜你喜欢
  • 1970-01-01
  • 2013-03-06
  • 2015-08-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多