Created
July 28, 2019 05:29
-
-
Save akashkahalkar/fcbf7901f7085c7b30d5b5efebe2b405 to your computer and use it in GitHub Desktop.
Create app icon for iPhone
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class func imageWith(name: String?) { | |
//sizes = [Int] | |
sizes.forEach { (value) in | |
let frame = CGRect(x: 0, y: 0, width: value, height: value) | |
let nameLabel = UILabel(frame: frame) | |
nameLabel.textAlignment = .center | |
nameLabel.backgroundColor = .black | |
nameLabel.textColor = .white | |
var fontSize = 25 | |
if value == 120 { | |
fontSize = 50 | |
} else if value == 180 { | |
fontSize = 60 | |
} | |
nameLabel.font = UIFont.boldSystemFont(ofSize: CGFloat(fontSize)) | |
nameLabel.text = String(name?.prefix(2) ?? "Aa") | |
//logic i wanted to port to macos | |
UIGraphicsBeginImageContext(frame.size) | |
if let currentContext = UIGraphicsGetCurrentContext() { | |
nameLabel.layer.render(in: currentContext) | |
let nameImage = UIGraphicsGetImageFromCurrentImageContext() | |
//function which will save images to documents directory | |
saveImageToDocumentDirectory(image: nameImage, name: name ?? "dummy", value: value) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment