[英]How to add button to MBProgressHUD, relative to text label?
I want to add a custom cancel button to MBProgressHUD
, and I want it to be just right of text label. 我想向
MBProgressHUD
添加自定义取消按钮,并且希望它恰好在文本标签的右边。 But MBProgresHUD
is drawn by overriding drawRect
method, so, while I can add button as subview to HUD, i don't know how large text label will be so I can position my button properly. 但是
MBProgresHUD
是通过重写drawRect
方法绘制的,因此,尽管我可以将按钮添加为HUD的子视图,但我不知道文本标签的大小,因此可以正确放置按钮。
How can this be achieved? 如何做到这一点?
I'm not sure this is possible directly using MBProgressHUD
. 我不确定直接使用
MBProgressHUD
是否可能。 Not without rewriting much of it. 并非没有大量重写。
One option could be to just add your own button as a subview of the view you are adding the HUD to that would just close the HUD or cancel the action. 一种选择是仅将您自己的按钮添加为要向其添加HUD的视图的子视图,这只会关闭HUD或取消操作。
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 50, 50, 50)]; // made up coords here
// set button stuff here
[self.view addSubview:button];
You will need to set the button actions, background or image (for look and feel), then add it to your view. 您将需要设置按钮操作,背景或图像(用于外观),然后将其添加到视图中。 Basically 2 views to achieve what you need.
基本上有2种视图可满足您的需求。 HUD and button.
HUD和按钮。 Probably a lot easier than rewriting
MBProgressHUD
to allow buttons. MBProgressHUD
允许按钮容易得多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.