设置配件按钮框架

问题描述 投票:0回答:1

在我的iPhone应用程序中,我在每个单元格中添加了一个附件按钮。

这是我的代码如下:

    ContactCell *contactCell = (ContactCell *)[tableView dequeueReusableCellWithIdentifier:kCellID];
    if (contactCell == nil) {
        contactCell = [[ContactCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kCellID];
        contactCell.frame = CGRectMake(0.0, 0.0, 320.0, ROW_HEIGHT);
    }

    UIImage *callButtonImage=[UIImage imageNamed:@"call-person.png"];
    UIButton *button =[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0.0, 0.0, 200, ROW_HEIGHT);
    [button setBackgroundImage:callButtonImage forState:UIControlStateNormal];

    ContactWrapper *cellWrapper = nil;  
            [button addTarget:self action:@selector(askCallForClientContact:) forControlEvents:UIControlEventTouchUpInside];
            contactCell.accessoryView = button;

我将按钮框设置为:button.frame=CGRectMake(0.0, 0.0, 200, ROW_HEIGHT);

但似乎按钮框架比200更小。当我点击一个单元格并假设有一个按钮时,会出现didSelectRowAtIndexPath事件,而不是askCallForClientContact:事件。如何设置配件按钮的框架?我需要200宽?

iphone ios
1个回答
0
投票

不,你不能改变accessoryView的框架。作为替代方案,您可以向单元格添加子视图

[cell.contentView addSubview:aView];
© www.soinside.com 2019 - 2024. All rights reserved.