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;

    }

  • 相关阅读:
    2013,爱上暗色调
    [转]Sublime Text 使用介绍、全套快捷键及插件推荐
    委托、事件
    ASP.NET中常用的三十三种代码 .NET技术 / ASP.NET
    台湾综艺节目
    C# 中的委托和事件
    ASP.net 静态化页面之的URL重写
    源码
    毕业5年决定你的一生
    常见错误 不能打开注册表关键字
  • 原文地址:https://www.cnblogs.com/happyEveryData/p/5515502.html
Copyright © 2011-2022 走看看