2011-09-16 33 views
0

我試圖創建一個UIImageView一個簡單的條形圖,我到目前爲止的代碼是:動畫一個UIImageView爲圖表

- (void)createNewBarWithValue:(float)percent andImage:(UIImageView *)newBar 
{ 
    CABasicAnimation *scaleToValue = [CABasicAnimation animationWithKeyPath:@"transform.scale.y"]; 
    scaleToValue.toValue = [NSNumber numberWithFloat:percent*2.5]; 
    scaleToValue.fromValue = [NSNumber numberWithFloat:0]; 
    scaleToValue.duration = 1.5f; 
    scaleToValue.delegate = self; 

    newBar.layer.anchorPoint = CGPointMake(0.5, 1); 

    [newBar.layer addAnimation:scaleToValue forKey:@"scaleUp"]; 
    CGAffineTransform scaleTo = CGAffineTransformMakeScale(1.0f, percent * 2.5); 
    newBar.transform = scaleTo; 
} 

所有我在這裏做的是非常簡單的只是用轉型來獲得動畫。動畫的結果可以看到here

現在我想要做的實際上是有我的最終圖表所示:

enter image description here

現在的一個問題,我現在在這裏看到的是在上面的角的邊框。我不能用我目前擁有的東西來做到這一點。那麼做這件事最簡單的解決方法是什麼?

回答

0

試試這個:

newBar.layer.cornerRadius = 5;//or any other value 

不幸的是,這將設置所有四個角的半徑。您可能必須隱藏底部兩個角並相應地調整高度,或者在newBar的底部頂部添加另一個圖像視圖。

+0

我想到了這一點......但正如你指出的那樣,它會爲所有4個角落。隱藏底角的最佳方法是什麼? – aherlambang

+0

在newBar的底部添加另一個圖像視圖,其形狀爲紅色矩形 – 2011-09-16 18:38:42

+0

,我剛剛嘗試過,但它沒有給我任何角落半徑。是否還有其他需要更改的設置那 – aherlambang