2012-05-11 38 views
0

不知道標題是否非常清晰,但我不知道我要找的東西的確切名稱。我有一個由UIButtons組成的網格(基本上是一個音序器)。我想在此圖像中類似於垂直線的線路(每一行的第8和第9個按鈕之間。在現有元素上顯示進度線

enter image description here

所以基本上,當播放我的格我想表明的進展不知道如何我可以這樣做嗎?使用什麼樣的元素等等。

回答

2

您可以添加非常窄,1或1.5像素的UIView。將背景顏色設置爲白色或漸變。將此視圖添加到與按鈕相同的子視圖。

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(100.0, 0.0, 1.5, 320.0)]; 
lineView.backgroundColor = [UIColor whiteColor]; 
[parentView addSubview:lineView]; 

要顯示進度,您需要知道剩下多少錢才能完成。取這個值併除以320得到lineView的高度。

CGRect frame = CGRectMake(100.0, 0.0, 1.5, 0); 
lineView.frame = frame; // 0% complete 

frame = CGRectMake(100.0, 0.0, 1.5, 160.0); 
lineView.frame = frame; // 50% complete 

frame = CGRectMake(100.0, 0.0, 1.5, 320.0); 
lineView.frame = frame; // 100% complete 

這就是主意。希望這個幫助。

更新到豎線在屏幕上

UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 1.5, 320.0)]; 
lineView.backgroundColor = [UIColor whiteColor]; 
[parentView addSubview:lineView]; 

由於進度移動由

- (void)progressWithValue(CGFloat)progress { 
    CGRect frame = lineView.frame; 
    frame.origin.x = progress; // Change x position 
    lineView.frame = frame; 
} 
+0

而不是改變進度的位置? – networkprofile

+0

您可以選擇完整的線條並移動原點,也可以更改高度或寬度較大的線條框。 – bbarnhart

+0

這是假設全寬度是320px?因爲我看不到如何改變框架的高度會使它移動。謝謝你的幫助! – networkprofile

0

您可以使用UISlider顯示事件或活動的進度(不太清楚您的代碼)並根據您的需要進行自定義。您可以查看UICatalog sample code by Apple以獲得定製UISlider以及其他元素的技術訣竅或UISlider Tutorial

+0

能否UISlider定製,雖然多少?在我的例子中的行涵蓋了很多UI元素 – networkprofile

+0

是的,它可以定製,它的框架將等於你設置的大小。我以前試過。 –