zoukankan      html  css  js  c++  java
  • 获取系统相册图片进行九宫布局

    - (void)openCamera

    {

        NSLog(@"打开相机");

        [self imagePickerControllerType:UIImagePickerControllerSourceTypeCamera];

    }

     - (void)imagePickerControllerType:(UIImagePickerControllerSourceType)sourceType

    {

        UIImagePickerController *pickerController = [[UIImagePickerController alloc] init];

        pickerController.sourceType = sourceType;

        pickerController.delegate = self;

        [self.navigationController presentViewController:pickerController animated:YES completion:nil];

    }

    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info

    {

        // 获取当前点击的图片名字

        UIImage *imageName = info[UIImagePickerControllerOriginalImage];

        [self.publishPhotoView addPhotoName:imageName];

        [self dismissViewControllerAnimated:YES completion:nil];

    }

    在自己定义PhotoView中进行布局

    - (void)layoutSubviews {

        [super layoutSubviews];

        // 设置图片的尺寸和位置

        NSUInteger count = self.subviews.count;

        int maxCol = 4;

        CGFloat imageWH = 70;

        CGFloat imageMargin = 10;

         for (int i = 0; i<count; i++) {

            UIImageView *photoView = self.subviews[i];

            int col = i % maxCol;

            photoView.x = col * (imageWH + imageMargin);

            

            int row = i / maxCol;

            photoView.y = row * (imageWH + imageMargin);

            photoView.width = imageWH;

            photoView.height = imageWH;

        }

    }

     - (void)addPhotoName:(UIImage *)photpName

    {

        UIImageView *photo = [[UIImageView alloc] init];

        photo.backgroundColor = [UIColor yellowColor];

        [self addSubview:photo];

        

        photo.image = photpName;

    }

  • 相关阅读:
    自定义Filter服务
    filter 以及 orderBy的使用
    ng-repeat-start ng-repeat-end 的使用
    ng-repeat 与ng-switch的简单应用
    ng-bind-html 的使用
    Oracle instr用法
    Oracle left查询案例
    Oracle case用法
    mysql 导出导入sql
    Gson解析复杂JSON对象
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5515502.html
Copyright © 2011-2022 走看看