开发者

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 e开发者_如何学Goxcept 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?


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜