带有图像点击问题的iphone UI按钮

时间:2011-09-21 16:11:13

标签: iphone image uibutton

我的应用程序中的背景图像中有3个UI按钮...

对于所有这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];

希望有所帮助......

1 个答案:

答案 0 :(得分:0)

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

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

并删除行[segment release];,因为您将创建autoreleased对象。