【iOS】AMPathPopUpButton

来源:互联网 发布:linux shell wait命令 编辑:程序博客网 时间:2024/06/11 15:15

在Mac OS开发中,我们可以使用AMPathPopUpButton控件来实现用户选择文件夹路径的功能,非常方便实用。

步骤一、首先我们需要在项目工程中添加Automator.framework系统库文件。在ViewController.h文件中,使用@class 向前引用AMPathPopUpButton类。

             

步骤二、打开Main.storyboard,在Show the Object library面板中选中Automator Path Pop Up Button 控件,并将其拖入到故事版中:


步骤三、在Show the Attributes inspector中可以对AMPathPopUpButton控件的属性进行设置。Path Types分为:Applications(应用)、Directories(目录)、Files(文件)这三种类型,Choosen 设置控件显示的是New Paths(新地址)还是Existing Paths(已存在的地址),Show 一般选择 Standard Paths即可。

  

步骤四、运行效果:


步骤五、获取AMPathPopUpButton控件选中的路径地址以及为其设置新的地址:

首先需要打开Show the Bindings inspector,勾线Bind to 并选中对应的ViewController,设置Model Key Path 为self.mPath(自定义值)。然后在ViewController.h文件中为其添加@property(nonatomic,copy)NSString*mPath;

通过mPath即可获取AMPathPopUpButton当前选中的路径地址,也可以将新的地址赋值给mPath对AMPathPopUpButton进行新地址设置。