2014-03-03 56 views
0

我想知道如何將一個活動指示器(在HUD的中間)添加到此正確的方法(我正在嘗試在其上創建一個hud)如何將UIActivityIndi​​cator添加到drawRect中

- (void)drawRect:(CGRect)rect { 

// Sets the rectangle to be 96 X 96. 
const CGFloat boxWidth = 120.0f; 
const CGFloat boxHeight = 120.0f; 

// This method is used to calculate the position of the rectangle. 
CGRect boxRect = CGRectMake(roundf(self.bounds.size.width - boxWidth)/2.0f, roundf(self.bounds.size.height - boxHeight)/2.0f, boxWidth,boxHeight); 

// This draws the rectangle with rounded corners. 
UIBezierPath *roundedRect = [UIBezierPath bezierPathWithRoundedRect:boxRect cornerRadius:10.0f]; 

[[UIColor colorWithWhite:0.0f alpha:0.75] setFill]; 

[roundedRect fill]; 

[[UIColor whiteColor] set]; // Sets the color of the font to white. 

UIFont *font = [UIFont boldSystemFontOfSize:16.0f]; // Sets the size of the font to 16. 

CGSize textSize = [self.text sizeWithFont:font]; 

// Calculates where to draw the text. 
CGPoint textPoint = CGPointMake(self.center.x - roundf(textSize.width/2.0f), self.center.y - roundf(textSize.height/2.0f) + boxHeight/4.0f); 


// Draws the text on the rectangle. 
[self.text drawAtPoint:textPoint withFont:font]; 
} 

謝謝!

+0

您的drawRect:肯定是在自定義視圖中。所以,只需在Storyboard中的這個視圖中拖動你的活動指標。 –

回答

1

你不知道。活動指示器是一種視圖,因此您可以將其添加爲HUD的子視圖,並且它將自行繪製。

相關問題