Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/103.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios UITableViewCell的背景色有问题_Ios_Uitableview_Uicolor - Fatal编程技术网

Ios UITableViewCell的背景色有问题

Ios UITableViewCell的背景色有问题,ios,uitableview,uicolor,Ios,Uitableview,Uicolor,我正在设置我的UITableViewCell的backgroundColor,如下所示: cell.backgroundColor = [UIColor colorWithPatternImage: [UIImage imageNamed:@"background.png"]]; 除了电池的“端盖”,它看起来很好。端盖(圆角开始处)的颜色与单元的中间部分不同我是否也需要提供端盖的图像?不太确定端盖是什么。但是我想说,如果你用一个图像作为你的细胞,

我正在设置我的
UITableViewCell
backgroundColor
,如下所示:

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

除了电池的“端盖”,它看起来很好。端盖(圆角开始处)的颜色与单元的中间部分不同我是否也需要提供端盖的图像?

不太确定端盖是什么。但是我想说,如果你用一个图像作为你的细胞,它应该占据整个细胞。你应该在这一点上定义你的细胞的大小。请参见下面的布局子视图了解我的意思

#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
检查。