【发布时间】:2014-07-20 00:31:43
【问题描述】:
我有这样的自定义 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;
在 cellForIndex.. 我添加 LongPress 识别器。长按时调用函数 animateLock。
- (void) animateLock
{
[self.deleteButton setImage:[UIImage imageNamed:@"lock"] forState:UIControlStateNormal];
self.deleteButton.hidden = NO;
self.deleteButton.backgroundColor = [UIColor redColor];
}
奇怪的是按钮变得可见并且图像已更改,但 backgroundColor 被忽略(无论我设置哪种颜色)。
为什么?
【问题讨论】:
-
您的 nameLabel 是否有覆盖它的背景颜色集?否则,请检查以确保 cell.contentView 背景颜色也是清晰的颜色。
-
No 在情节提要中,我将按钮设为蓝色并保持蓝色,因此它没有被任何东西覆盖。如果我在 init 方法中将背景颜色设置为红色,它会显示为红色,但只有在此方法中它完全忽略颜色设置。
-
如果你为按钮添加图像,那么它如何显示背景颜色?
-
图像几乎都是透明的。
标签: ios uitableview uibutton background-color