2011-11-22 34 views

回答

1

以及最简单的是设置你的UIView为图像的背景...

self.view.backgroundColor = [[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"myimage.png"]]; 
+0

澄清:是的,它可以在代码中绘制它,但预渲染图像(PTBG的建议)是迄今为止最好的选择。 – sosborn

+0

有没有不使用背景图片的方法? – Safari

+0

我不认为它是最好的选择。对于传说来说,颜色很重要。有一次,你想从蓝色到红色,另一次你想它从黑色到绿色单色......等等。 – debleek63

1

好,你必须画出它。使UIView一个子类,实现drawRect方法:

-(void)drawRect:(CGRect)dummy 
{ 
    for (int i = 0; i < NR_SEGMENTS; i++) 
    { 
     [[self colorForIndex:i] setFill]; 
     UIRectFill(CGRectMake(0, 0, 
           CGRectGetWidth(self.bounds)/NR_SEGMENTS, 
           CGRectGetHeight(self.bounds))); 
     CGContextTranslateCTM(UIGraphicsGetCurrentContext(), 
           CGRectGetWidth(self.bounds)/NR_SEGMENTS, 
           0); 
    } 
} 

colorForIndex:应该返回一些色彩。