ios - 如何将 UIActivityIndi​​cator 添加到 drawRect

标签 ios subview uiactivityindicatorview hud

我想知道如何将事件指示器(在 HUD 的中间)添加到此 drawrect 方法(我正在尝试创建一个带有事件的 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];
}

谢谢!

最佳答案

你不知道。事件指示器是一种 View ,因此您可以将它添加为 HUD 的 subview ,它会自行绘制。

关于ios - 如何将 UIActivityIndi​​cator 添加到 drawRect,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22158101/

相关文章:

iphone - 查找当前位置和指定位置之间的道路距离

ios - watchOS 2 使用 CocoaPods

ios - 如何将 "Cancel"AVAudioSession 连接到另一个 View Controller ?

cocoa - 适用于 Mac OS X 的 UIActivityIndi​​catorView?

ios - 切换方向时 UIBarButtonItem 重置

ios - 如何制作一个仅在应用程序首次打开时显示的 View Controller ?

iphone - 使用 Alpha 设置为 subview 添加背景色

ios - 添加到 ImageView 的 subview 不合适

ios - Swift:获取特定类型的所有 subview 并添加到数组

swift - 如何实现单例微调器(事件指示器)?