2013-04-02 36 views
0

我有一个具有图案背景的视图。之前,我将图像切分为大小,以便它们非常大。为View创建图案背景

我认为这是一个更好的方式与背景颜色和在上面的图案图像接近,因此影像会更小,更少的内存等

buttonView =[[UIView alloc] initWithFrame:CGRectMake(0, logoView.bounds.size.height, screen.size.width, 232)]; 
buttonView.autoresizingMask = UIViewAutoresizingFlexibleHeight; 
// UIImageView *bgButtonView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, buttonView.bounds.size.width, buttonView.bounds.size.height)]; 
// NSString *bgButtonViewFilePath = [[NSBundle mainBundle] pathForResource:@"bg-welcomeButtonView" ofType:@"png"]; 
// UIImage *bgButtonImg = [[UIImage alloc] initWithContentsOfFile:bgButtonViewFilePath]; 
// [bgButtonView setImage:bgButtonImg]; 
// [buttonView addSubview:bgButtonView]; 
    buttonView.backgroundColor = [[UIColor blueColor] initWithPatternImage:[UIImage imageNamed:@"bg-ButtonViewPattern"]]; 

在最后一行中我尝试设置我的图案覆盖蓝色。不幸的是整个视图显示为白色。如果我只有blueColor,它会显示纯蓝色,所以不能确定上述内容是否有错。

我的图像模式在下面,它是一个白色和透明像素的PNG。

Pattern Image

+0

你有没有尝试在图像名称中包含扩展名? – Undo

+0

是的,没有区别不幸 – StuartM

+0

注意:我发现了这个问题,等待版主无法回答自己的问题 – StuartM

回答

0

您可以设置图形作为背景色是这样的:

buttonView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg-ButtonViewPattern"]]; 

如果图像是比较小的,你可以与需要覆盖的颜色也很多版本。