【问题标题】:How to make transparent UIButton in UITableView Cell如何在 UITableView Cell 中制作透明的 UIButton
【发布时间】:2011-10-05 10:21:56
【问题描述】:

当我的 .Xib 文件加载时,UITableViewCell 被黑色背景填充,为此,我正在使用

cell.contentView.backGroundColor = [UIColor blackColor]

但是在UITableViewCell 中,一个UIButton 带有“自定义”按钮类型是以编程方式生成的 所以覆盖UIButton的区域不是transparent(或单元格背景-黑色不显示),它是白色的,,,

我想用透明背景制作UIButton

我该怎么做?

【问题讨论】:

    标签: iphone objective-c ios


    【解决方案1】:
    UIButton *button;
    button.backgroundColor = [UIColor clearColor];
    

    【讨论】:

    • 您需要先将按钮类型更改为自定义。 @prithvi
    【解决方案2】:
    try this one it work for me
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
            [button addTarget:self 
                       action:@selector(aMethod:)
             forControlEvents:UIControlEventTouchDown];
            [button setTitle:@"Show View" forState:UIControlStateNormal];
            button.frame = CGRectMake(0.0, 5.0, 160.0, 40.0);
            [button setBackgroundColor:[UIColor clearColor]];
            [cell.contentView addSubview:button];
    

    【讨论】:

      【解决方案3】:

      您为什么不制作按钮图像以及要显示的文本并将其添加为按钮背景并自定义按钮类型。

      【讨论】:

        猜你喜欢
        • 2015-10-23
        • 2021-10-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-11-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多