1. 程式人生 > >頭像圖片裁剪

頭像圖片裁剪

fig tle 選中 def eight 時間 alloc code oid

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]; }

頭像圖片裁剪