SundayMonday
SundayMonday

Reputation: 19727

Trouble with backgroundColor of UITableViewCell

I'm setting the backgroundColor of my UITableViewCell like this:

cell.backgroundColor = [UIColor colorWithPatternImage:
                        [UIImage imageNamed:@"background.png"]];

It looks fine except for the "end caps" of the cell. The end caps (where the rounded corners start) are colored differently like the middle portion of the cell. Do I need to provide images for the end caps too?

Upvotes: 0

Views: 288

Answers (1)

owen gerig
owen gerig

Reputation: 6172

not really sure what the end caps are. but i would say if ur using an image for your cell it should take up the whole cell. and you should be defining the size of your cells at that point. see layout subviews below for what i mean

#import "CustomCell.h"


@implementation CustomCell
@synthesize primaryLabel,myImageView;
- (id)initWithFrame:(CGRect)frame reuseIdentifier:(NSString *)reuseIdentifier {

    if (self = [super initWithFrame:frame reuseIdentifier:reuseIdentifier]) {

        // Initialization code

        primaryLabel = [[UILabel alloc]init];

        primaryLabel.textAlignment = UITextAlignmentLeft;

        primaryLabel.font = [UIFont systemFontOfSize:20];

        myImageView = [[UIImageView alloc]init];

        [self.contentView addSubview:primaryLabel];

        [self.contentView addSubview:myImageView];

    }

    return self;

}

- (void)layoutSubviews {

    [super layoutSubviews];

    CGRect contentRect = self.contentView.bounds;

    CGFloat boundsX = contentRect.origin.x;

    CGRect frame;

    frame= CGRectMake(boundsX+10 ,0, 40, 40);

    myImageView.frame = frame;

    frame= CGRectMake(boundsX+70 ,5, 200, 25);

    primaryLabel.frame = frame;


}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [myImageView release];
    [primaryLabel release];
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {

    [super setSelected:selected animated:animated];

    // Configure the view for the selected state

}

@end

Upvotes: 1

Related Questions