Bra*_*Mcq 1 cocoa-touch uibutton uitableview uikit ios
我有一个UITableViewCell我要加五UIButtons.我以编程方式创建按钮,添加动作和图像.按钮放置在正确的位置,动作正常,标签已设置,但它们是清晰的.图像没有显示.
这是我用来创建其中一个按钮并将它们添加到单元格中,此代码位于tableView:cellForRowAtIndexPath::
if ([[self.compCompletion objectForKey:@"Key" isEqualToString:@"YES"]) {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(11, 6, 21, 21);
button.tag = 1;
[button addTarget:self action:@selector(changeCompStatus:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"Comp-Completed.png"] forState:UIControlStateNormal];
[button setContentMode:UIViewContentModeScaleToFill];
[cell.contentView addSubview:button];
}
else {
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.frame = CGRectMake(11, 6, 21, 21);
button.tag = 1;
[button addTarget:self action:@selector(changeCompStatus:) forControlEvents:UIControlEventTouchUpInside];
[button setImage:[UIImage imageNamed:@"Comp-Uncompleted.png"] forState:UIControlStateNormal];
[button setContentMode:UIViewContentModeScaleToFill];
[cell.contentView addSubview:button];
}
Run Code Online (Sandbox Code Playgroud)
我试过添加:[button setEnabled:YES];,[button setHidden:NO];并且[button setNeedsDislpay];没有运气的过程.如何获得显示图像的按钮?
编辑:
我的形象存在,UIImage创建的,我可以拉UIImage出来的UIButton,并将其保存到一个文件中.我已经浏览了UIButton控制外观的每个属性并更改了它们.我也试过一个空UIButton的类型UIButtonTypeRoundedRect和UIButtonTypeAddContact.我现在相信这与UITableViewCell不喜欢有关UIButtons,或者我是如何添加UIButton的UITableViewCell.
| 归档时间: |
|
| 查看次数: |
4108 次 |
| 最近记录: |