【问题标题】:custom UIButton with image带有图像的自定义 UIButton
【发布时间】:2012-06-22 07:02:23
【问题描述】:

我正在尝试设置单元格的附件视图,即UIButton。但是没有显示出来。

这里是代码

UIButton *accessory = [UIButton buttonWithType:UIButtonTypeCustom];
[accessory setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
[cell setAccessoryView:accessory];

【问题讨论】:

  • 试试 [cell.contentView 附件];并根据需要定位配件。

标签: iphone ios uitableview uibutton


【解决方案1】:

调用[accessory sizeToFit];根据图片调整大小。

【讨论】:

    【解决方案2】:

    你需要像这样为这个配件设置一个框架

    UIButton *accessory = [UIButton buttonWithType:UIButtonTypeCustom];
    [accessory setImage:[UIImage imageNamed:@"plus.png"] forState:UIControlStateNormal];
    //Set the accessory frame
    accessory.frame = CGRectMake(0, 0, 100, 100);
    

    【讨论】:

      【解决方案3】:
      UIView* accessoryView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 24, 50)];
      UIImageView* accessoryViewImage = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"arrow.png"]];
      accessoryViewImage.center = CGPointMake(12, 25);
      [accessoryView addSubview:accessoryViewImage];
      [cell setAccessoryView:accessoryView];
      [accessoryViewImage release];
      [accessoryView release];
      

      就这样吧。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-07-08
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-31
        相关资源
        最近更新 更多