I used this guide: http://www.bdunagan.com/2009/06/28/custom-uitableviewcell-from-a-xib-in-interface-builder to be able to create my own custom UITableViewCell with a nice background image in interface builder. But I would like the style of the cell to be UITableViewCellStyleSubtitle to still be able to use textLabel and detailTextLabel for my custom cell. Can I in some way set the style of the cell in interface builder?
Now only the textLabel is set when using:
cell.textLabel.text = @"Title";
cell.detailTextLabel.text = @"Details";
Also I use a transparent image as background, but textLabel has white background. Can I change this in interface builder? Or do you think I should just add my own labels to the custom cell in interface builder and skip the standard textLabel and detailTextLabel?
Thanks for your help!
Use Option B. Either fully use your own custom cell, or fully use Apple's styled cell. Trying to mix and match is not forward compatible.
If you want a convenient property for the detailTextLabel, subclass UITableViewCell
and return the UILabel
you create in the nib. Give it a different name than detailTextLabel
.
If you want to use detailTextLabel in a custom button, follow these steps:
// MYTableViewCell.h:
@interface MYTableViewCell : UITableViewCell
@end
// MYTableViewCell.m
@interface MYTableViewCell ()
@property (nonatomic, weak) IBOutlet UILabel* detailLabel;
@end
-detailTextLabel
@implementation MYTableViewCell
- (UILabel*)detailTextLabel
{
return self.detailLabel;
}
@end
Set the custom class for your tableview cell to be MYTableViewCell and associate your UILabel with your new IBOutlet. Future calls to detailTextView on your tableview cell will now correctly return the proper text view. In this way, you can mix custom and OS provided tableview cells without worrying about the detailTextView.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With