Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

random photos #1

Open
phimage opened this issue Apr 6, 2017 · 1 comment
Open

random photos #1

phimage opened this issue Apr 6, 2017 · 1 comment

Comments

@phimage
Copy link
Member

phimage commented Apr 6, 2017

Photos must be categorized

The user defined properties could be xxx.image.category

For each categories we must find free-to-use images

Framework could load UIImage or NSImage, compute the name using pattern and random numbers

@phimage
Copy link
Member Author

phimage commented Apr 6, 2017

There is a big issue with photos, how to load images in Interface Builder

An UIImage created in code it's ok

public extension UIImage {
  public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1)) {
    let rect = CGRect(origin: .zero, size: size)
    UIGraphicsBeginImageContextWithOptions(rect.size, false, 0.0)
    color.setFill()
    UIRectFill(rect)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()

    guard let cgImage = image?.cgImage else { return nil }
    self.init(cgImage: cgImage)
  }
}

But using UIImage(named:... , or with Data from bundle

 else if key == "image" {
                if let path = Bundle.main.path(forResource: "first", ofType: "jpg") {
                  let url = URL(fileURLWithPath: path)
                        let data = try! Data(contentsOf: url)
                        
                        let value = UIImage(data: data)
                        view.setValue(value, forKey: viewKey)
                }
            }

EDIT: I think the bundle must be change to something like that let myBundle = Bundle(forClass: self.dynamicType)

some other code to do advanced code

override func prepareForInterfaceBuilder() {
    let processInfo = NSProcessInfo.processInfo()
    let environment = processInfo.environment
    let projectSourceDirectories : AnyObject = environment["IB_PROJECT_SOURCE_DIRECTORIES"]!
    let directories = projectSourceDirectories.componentsSeparatedByString(":")

    if directories.count != 0 {
        let firstPath = directories[0] as String
        let imagePath = firstPath.stringByAppendingPathComponent("PrepareForIBTest/Test.jpg")

        let image = UIImage(contentsOfFile: imagePath)
        self.image = image
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant