如何将UIActivityIndi​​cator添加到drawRect中

时间:2014-03-03 21:43:24

标签: ios subview uiactivityindicatorview hud

我想知道如何在这个简化方法中添加一个活动指示符(在HUD中间)(我正在尝试创建一个带有活动的hud)

- (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];
}

谢谢!

1 个答案:

答案 0 :(得分:1)

你没有。活动指示器是一种视图,因此您可以将其添加为HUD的子视图,它将自行绘制。