我創建萬畝自定義UITableViewCells在- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
像這樣:自定義的UITableViewCell內設置的UIButton的contentMode沒有顯示出效果
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomTableViewCell" owner:self options:nil];
CustomTableViewCell *cell = [topLevelObjects objectAtIndex:0];
使用InterfaceBuilder中我已經將這個小區的廈門國際銀行內包含到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]' – Stonz2