【发布时间】:2016-02-25 18:58:42
【问题描述】:
我正在- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中创建 mu 自定义 UITableViewCells,如下所示:
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
CustomTableViewCell *cell = [topLevelObjects objectAtIndex:0];
使用 InterfaceBuilder,我已将此单元格的 xib 中包含的两个按钮的内容模式设置为 AspectFit,但它们的显示方式不保留纵横比。所以我在这个类中添加了以下代码:
- (id) initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
NSLog(@"running initwithstyle");
self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
if (self) {
[[deleteButton imageView] setContentMode:UIViewContentModeScaleAspectFit];
[[saveButton imageView] setContentMode:UIViewContentModeScaleAspectFit];
}
return self;
}
这个函数甚至没有运行。我也尝试子类化displayLayer,但显然也没有被调用。我应该继承什么函数,以便我可以在我的 Xib 中设置按钮的内容模式,为什么在 Xib 中设置内容模式没有效果?
【问题讨论】:
-
您可以在上面节省一行代码。而不是创建一个数组,然后在索引 0 处获取对象,只需执行
[[[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil] firstObject]
标签: ios objective-c uitableview uibutton