2011-11-22 88 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:應該返回一些色彩。