Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.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
Ios UITableViewCell中的UIButton设置背景色无效_Ios_Uitableview_Uibutton_Background Color - Fatal编程技术网

Ios UITableViewCell中的UIButton设置背景色无效

Ios UITableViewCell中的UIButton设置背景色无效,ios,uitableview,uibutton,background-color,Ios,Uitableview,Uibutton,Background Color,我有如下自定义UITableViewCell: @property (weak) IBOutlet UIDefaultServerButton * defaultButton; @property (weak) IBOutlet UILabel * nameLabel; @property (weak) IBOutlet UIRoundButton * deleteButton; @property (weak) IBOutlet NSLayoutConstraint * buttonHeigh

我有如下自定义UITableViewCell:

@property (weak) IBOutlet UIDefaultServerButton * defaultButton;
@property (weak) IBOutlet UILabel * nameLabel;
@property (weak) IBOutlet UIRoundButton * deleteButton;
@property (weak) IBOutlet NSLayoutConstraint * buttonHeight;
@property (weak) IBOutlet NSLayoutConstraint * buttonWidth;

@property id <TableViewCellDelegate> delegate;

- (void) setDefaultServer: (BOOL) def;
- (void) animateLock;
- (void) animateTrash;
奇怪的是,按钮变得可见,图像也发生了变化,但背景色被忽略了(无论我设置了哪种颜色)


为什么?

您拍摄的图像可能与按钮的大小相同。缩小图像或增加按钮的面积。

您使用的代码非常好,但背景色不可见的原因是背景图像隐藏了UIButton的背景色。您可以通过注释行来确认这一点

[self.deleteButton setImage:[UIImage ImageName:@“锁定”]用于状态:UIControlStateNormal]

然后按钮的背景将可见


如果您能详细说明为什么要设置按钮的红色背景,我将对此进行研究。

您的姓名标签是否可以设置一个覆盖它的背景颜色?否则,请检查以确保cell.contentView背景颜色也是清晰的颜色。不,在故事板中,我将按钮设置为蓝色,并保持蓝色,因此它没有被任何内容覆盖。如果我在init方法中将背景色设置为红色,它会显示为红色,但在这个方法中,它完全忽略了颜色设置。如果你为按钮添加图像,那么它如何显示背景色?图像几乎是透明的。不,它不可能是。请看上面的评论。图像是90%透明的,(就像轻触栏中的图标一样——四周轮廓都是透明的)我也能看到所有的东西,但事实并非如此
- (void) animateLock
{

    [self.deleteButton setImage:[UIImage imageNamed:@"lock"] forState:UIControlStateNormal];

    self.deleteButton.hidden = NO;

    self.deleteButton.backgroundColor = [UIColor redColor];

}