欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

头像图片裁剪

发布时间:2025/3/21 编程问答 37 豆豆
生活随笔 收集整理的这篇文章主要介绍了 头像图片裁剪 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

 

1.第三方 

TZImagePickerController.h

- (void)pushTZImagePickerController {// if (self.maxCountTF.text.integerValue <= 0) {// return;// }TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 columnNumber:3 delegate:self pushPhotoPickerVc:YES];// imagePickerVc.navigationBar.translucent = NO;#pragma mark - 五类个性化设置,这些参数都可以不传,此时会走默认设置imagePickerVc.isSelectOriginalPhoto = YES;// if (self.maxCountTF.text.integerValue > 1) {// 1.设置目前已经选中的图片数组// imagePickerVc.selectedAssets = YES; // 目前已经选中的图片数组// }imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮imagePickerVc.allowTakeVideo = YES; // 在内部显示拍视频按imagePickerVc.videoMaximumDuration = 10; // 视频最大拍摄时间[imagePickerVc setUiImagePickerControllerSettingBlock:^(UIImagePickerController *imagePickerController) {imagePickerController.videoQuality = UIImagePickerControllerQualityTypeHigh;}];// imagePickerVc.photoWidth = 1000;// 2. Set the appearance// 2. 在这里设置imagePickerVc的外观// imagePickerVc.navigationBar.barTintColor = [UIColor greenColor];// imagePickerVc.oKButtonTitleColorDisabled = [UIColor lightGrayColor];// imagePickerVc.oKButtonTitleColorNormal = [UIColor greenColor];// imagePickerVc.navigationBar.translucent = NO;imagePickerVc.iconThemeColor = [UIColor colorWithRed:31 / 255.0 green:185 / 255.0 blue:34 / 255.0 alpha:1.0];imagePickerVc.showPhotoCannotSelectLayer = YES;imagePickerVc.cannotSelectLayerColor = [[UIColor whiteColor] colorWithAlphaComponent:0.8];[imagePickerVc setPhotoPickerPageUIConfigBlock:^(UICollectionView *collectionView, UIView *bottomToolBar, UIButton *previewButton, UIButton *originalPhotoButton, UILabel *originalPhotoLabel, UIButton *doneButton, UIImageView *numberImageView, UILabel *numberLabel, UIView *divideLine) {[doneButton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];}];/*[imagePickerVc setAssetCellDidSetModelBlock:^(TZAssetCell *cell, UIImageView *imageView, UIImageView *selectImageView, UILabel *indexLabel, UIView *bottomView, UILabel *timeLength, UIImageView *videoImgView) {cell.contentView.clipsToBounds = YES;cell.contentView.layer.cornerRadius = cell.contentView.tz_width * 0.5;}];*/// 3. Set allow picking video & photo & originalPhoto or not// 3. 设置是否可以选择视频/图片/原图imagePickerVc.allowPickingVideo = NO;imagePickerVc.allowPickingImage = YES;imagePickerVc.allowPickingOriginalPhoto = YES;imagePickerVc.allowPickingGif = NO;imagePickerVc.allowPickingMultipleVideo = NO; // 是否可以多选视频// 4. 照片排列按修改时间升序imagePickerVc.sortAscendingByModificationDate = NO;// imagePickerVc.minImagesCount = 3;// imagePickerVc.alwaysEnableDoneBtn = YES;// imagePickerVc.minPhotoWidthSelectable = 3000;// imagePickerVc.minPhotoHeightSelectable = 2000;/// 5. Single selection mode, valid when maxImagesCount = 1/// 5. 单选模式,maxImagesCount为1时才生效imagePickerVc.showSelectBtn = NO;imagePickerVc.allowCrop = YES;// imagePickerVc.needCircleCrop = YES;// 设置竖屏下的裁剪尺寸NSInteger left = 30;NSInteger widthHeight = self.view.frame.size.width - 2 * left;NSInteger top = (self.view.frame.size.height - widthHeight) / 2;// imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);imagePickerVc.cropRect = CGRectMake(left, top, widthHeight, widthHeight);//imagePickerVc.allowPreview = NO;// Deprecated, Use statusBarStyle// imagePickerVc.isStatusBarDefault = NO;imagePickerVc.statusBarStyle = UIStatusBarStyleLightContent;// 设置是否显示图片序号imagePickerVc.showSelectedIndex = YES;#pragma mark - 到这里为止// You can get the photos by block, the same as by delegate.// 你可以通过block或者代理,来得到用户选择的照片.[imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {NSLog(@"");for (UIImage *img in photos) {self.image = img;}[self.tableView reloadData];}];[self presentViewController:imagePickerVc animated:YES completion:nil]; }

 

转载于:https://www.cnblogs.com/dujiahong/p/9944663.html

总结

以上是生活随笔为你收集整理的头像图片裁剪的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。