Iphone 我可以将uiprogressbar添加到uibutton吗

Iphone 我可以将uiprogressbar添加到uibutton吗,iphone,cocoa-touch,Iphone,Cocoa Touch,我想知道是否有可能以某种方式将UIButton子类化,以向其添加另一个组件,例如预加载程序或进度指示器 在伪代码中,我想到的是如下内容 UIButtonWithProgress *button =[[UIButtonWithProgress alloc]init] [button.progressbar setProgress:50%] 在iOS中,进度条的类是UIProgressView。如果您真的想将UIButton添加到UIProgressBar(如问题标题所示)。然后可以使用UIVi

我想知道是否有可能以某种方式将UIButton子类化,以向其添加另一个组件,例如预加载程序或进度指示器

在伪代码中,我想到的是如下内容

UIButtonWithProgress *button =[[UIButtonWithProgress alloc]init]

[button.progressbar setProgress:50%]

在iOS中,进度条的类是UIProgressView。如果您真的想将UIButton添加到UIProgressBar(如问题标题所示)。然后可以使用UIView方法
addSubView:
,例如:

UIButtonWithProgress* button = [[UIButtonWithProgress alloc] init];
UIProgressView* progressView = [[UIProgressView alloc] init];
[button addSubview:progressView];
progressView.progress = 0.5;
我认为您真正想要做的是创建自己的UIControl(因此您应该将其子类化)。您可以覆盖方法
drawRect:
以使用quartz绘制自己的进度条动画,并覆盖方法
touchesbeated:withEvent:
以检测用户点击自定义控件,以及添加任何其他希望控制控件状态的方法(例如进度级别)


注意:在我的代码示例中,我还提供了一个正确设置UIProgressBar进度的示例,以防您不清楚。

在iOS中,进度条的类是UIProgressView。如果您真的想将UIButton添加到UIProgressBar(如问题标题所示)。然后可以使用UIView方法
addSubView:
,例如:

UIButtonWithProgress* button = [[UIButtonWithProgress alloc] init];
UIProgressView* progressView = [[UIProgressView alloc] init];
[button addSubview:progressView];
progressView.progress = 0.5;
我认为您真正想要做的是创建自己的UIControl(因此您应该将其子类化)。您可以覆盖方法
drawRect:
以使用quartz绘制自己的进度条动画,并覆盖方法
touchesbeated:withEvent:
以检测用户点击自定义控件,以及添加任何其他希望控制控件状态的方法(例如进度级别)


注意:在我的代码示例中,我还提供了一个正确设置UIProgressBar进度的示例,以防您不清楚。

o.k,我知道您要做什么了。感谢
在我的代码示例中,我还举了一个**正确**设置UIProgressBar进度的示例,以防您不清楚。
否。进度在0.0和1.0之间浮动。好的,我知道你要去哪里。感谢
在我的代码示例中,我还举了一个**正确**设置UIProgressBar进度的示例,以防您不清楚。
否。进度在0.0和1.0之间浮动