基于 PickerController 功能模块封装相关 - iOS

 Now 第三方库 GitHub 地址飞机票: GitHub-JKImagePicker


首先包含所需的头文件,并添加代理.

Code 如下:

#pragma mark -更换头像相关

- (void)changeHeadImg {

alertConImg= [UIAlertController alertControllerWithTitle:nilmessage:nilpreferredStyle:UIAlertControllerStyleActionSheet];

[alertConImg addAction:[UIAlertAction actionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:^(UIAlertAction*_Nonnullaction) {

/**取消*/

}]];

[alertConImg addAction:[UIAlertAction actionWithTitle:@"拍照"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

/**拍照*/

}]];

[alertConImg addAction:[UIAlertAction actionWithTitle:@"从手机相册选取"style:UIAlertActionStyleDefaulthandler:^(UIAlertAction*_Nonnullaction) {

/**从手机相册选取*/

JKImagePickerController*imgPickerCon = [[JKImagePickerController alloc] init];

imgPickerCon.delegate=self;

imgPickerCon.showsCancelButton=YES;//显示取消按钮

imgPickerCon.allowsMultipleSelection=YES;//允许多个选择

imgPickerCon.minimumNumberOfSelection= 1;//最小选择的数量

imgPickerCon.maximumNumberOfSelection= 9;//最大选择的数量

imgPickerCon.selectedAssetArray=self.arrSletedHeadImg;//装载选择的照片

YQBaseNavigationController*navCon = [[YQBaseNavigationController alloc] initWithRootViewController:imgPickerCon];

[self presentViewController:navCon animated:YES completion:^{

//

}];

}]];

[self presentViewController:alertConImg animated:YES completion:^{

/**调相机功能PickerCon*/

}];

}

#pragma mark -相机或相册获取图片回调相关代理方法

- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAsset:(JKAssets*)asset isSource:(BOOL)source {

[imagePicker dismissViewControllerAnimated:YES completion:^{

//

}];

}

- (void)imagePickerController:(JKImagePickerController*)imagePicker didSelectAssets:(NSArray*)assets isSource:(BOOL)source {

self.arrSletedHeadImg= [NSMutableArray arrayWithArray:assets];

for(int i = 0; i

JKAssets*asset = [self.arrSletedHeadImg objectAtIndex:i];

ALAssetsLibrary*lib = [[ALAssetsLibrary alloc] init];

[lib assetForURL:asset.assetPropertyURLresultBlock:^(ALAsset*asset) {

//

}failureBlock:^(NSError*error) {

NSLog(@"YQMyInfoViewController.h --- imgPickerCon --- error --- %@", error);

}];

}

[imagePicker dismissViewControllerAnimated:YES completion:^{

/**点击完成回调*/

}];

}

- (void)imagePickerControllerDidCancel:(JKImagePickerController*)imagePicker {

[imagePicker dismissViewControllerAnimated:YES completion:^{

//

}];

}


el-date-picker是Element UI库中的一个日期选择器组件,用于在网页中选择日期。它提供了丰富的配置选项和交互功能,可以满足不同场景下的日期选择需求。 封装el-date-picker的步骤如下: 1. 引入Element UI库:在项目中引入Element UI库,可以通过CDN引入或者使用npm安装。 2. 创建封装组件:在Vue组件中创建一个新的组件,可以命名为DatePicker或其他合适的名称。 3. 在组件中使用el-date-picker:在新创建的组件中使用el-date-picker组件,并根据需要配置相关属性和事件。 4. 封装组件的props:根据需要,可以在封装组件中定义props来接收父组件传递的属性值,例如设置默认日期、禁用日期等。 5. 封装组件的事件:根据需要,可以在封装组件中定义事件来向父组件传递选择的日期值或其他相关信息。 6. 样式和布局:根据项目需求,可以对封装组件进行样式和布局的调整。 以下是一个简单的封装el-date-picker的示例代码: ```vue <template> <div> <el-date-picker v-model="selectedDate" :default-value="defaultDate" :disabled-date="disabledDate" @change="handleChange" ></el-date-picker> </div> </template> <script> export default { name: 'DatePicker', props: { defaultDate: { type: Date, default: null } }, data() { return { selectedDate: null } }, methods: { handleChange(date) { this.$emit('select', date); }, disabledDate(time) { // 自定义禁用日期的逻辑 // 返回true表示禁用该日期,返回false表示可选 return time.getTime() < Date.now(); } } } </script> <style scoped> /* 样式调整 */ </style> ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值