Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/image/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iphone UIbutton出现图像点击问题_Iphone_Image_Uibutton - Fatal编程技术网

iphone UIbutton出现图像点击问题

iphone UIbutton出现图像点击问题,iphone,image,uibutton,Iphone,Image,Uibutton,我有3个UIbuttons在我的应用程序中与背景图像 对于所有这3个按钮,如果指定了图像,则只有按钮的下半部分可单击,而上半部分根本不起作用 知道为什么吗 我试着为按钮添加颜色,以检查它们是否有正确的CGRect,但它看起来是正确的 这里有一些代码 UIButton* segment=[[UIButton alloc] initWithFrame:CGRectMake(0+(i* segmentWidth) , 0,segmentWidth, 34)]; segment.bac

我有3个UIbuttons在我的应用程序中与背景图像

对于所有这3个按钮,如果指定了图像,则只有按钮的下半部分可单击,而上半部分根本不起作用

知道为什么吗

我试着为按钮添加颜色,以检查它们是否有正确的CGRect,但它看起来是正确的

这里有一些代码

    UIButton* segment=[[UIButton alloc] initWithFrame:CGRectMake(0+(i* segmentWidth) , 0,segmentWidth, 34)];

    segment.backgroundColor = [UIColor redColor];

    [segment addTarget:self action:@selector(segmentActionButton:) forControlEvents:UIControlEventTouchUpInside];

    [segment setTag:i];

    segment.titleLabel.font=[UIFont fontWithName:@"Arial" size:12.0];

    segment.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin;

    [segment setTitle:[mItems objectAtIndex:i] forState:UIControlStateNormal];
    [segment setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];


        [segment setBackgroundImage:[UIImage imageNamed:SEGMENT_IMAGE_INACTIVE_MAP] forState:UIControlStateNormal];

        [segment setBackgroundImage:[UIImage imageNamed:SEGMENT_IMAGE_ACTIVE_MAP] forState:UIControlStateHighlighted];


    [self addSubview:segment];
    [mButtonArray addObject:segment];
    [segment release];

希望对您有所帮助。

可能是因为您正在以
alloc+initWithFrame
的方式创建按钮而发生错误。我不确定,但尝试以以下方式创建按钮:

UIButton* segment = [UIButton buttonWithType:UIButtonTypeCustom];
segment.frame = CGRectMake(0+(i* segmentWidth) , 0,segmentWidth, 34);

并删除行
[段释放]您将创建
自动删除的
对象。

显示代码将有助于解决您的问题。您是否使用IB在窗口中设置它们?尝试过,但仍然不起作用…我的意思是只有下半部分起作用。

上半部分仍然无法单击“启用…”。。。