iOS APP/SWIFT #3 (4–1) using iOS SDK to make a beautiful card

Load an iron man image with 1000 x 1000 pixels

using .contentMode : scaleAspecFit at Frame change to 1000x2000 pixels

using .contentMode : scaleToFill at Frame change to 1000x2000 pixels

using .contentMode : scaleAspecFill at Frame change to 1000x2000 pixels

And then add the text label, set the front size, color, background color.

Using CGAffineTransform to rotated iron man image and then add iron man and messageLabel to a subView of spaceImage

using loop function to add stars around the spaceImage

import UIKit

let ironManImage = UIImage (named: "iron_man.png")
let ironManImageView = UIImageView(image: ironManImage)
ironManImageView.frame = CGRect(x: 0, y: 80, width: 1000, height: 1000)
//set image position and size
ironManImageView.backgroundColor = UIColor (red: 0, green: 0, blue: 0, alpha: 0.2)
//set imageview background color

//Practice for different content mode
//ironManImageView.frame = CGRect(x: 0, y: 0, width: 1000, height: 2000)
//ironManImageView.contentMode = .scaleAspectFit
//ironManImageView
//
//ironManImageView.contentMode = .scaleToFill
//ironManImageView
//
//ironManImageView.contentMode = .scaleAspectFill
//ironManImageView
//
//ironManImageView.frame = CGRect(x: 0, y: 0, width: 1000, height: 1000)
//ironManImageView.backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0)

let messageLabel = UILabel (frame: CGRect(x: 350, y: 120, width: 300, height: 100)) //Creat label position and size
messageLabel.text = " Let's Fly to Cosmos~~~🚀" //set character of text
messageLabel.textColor = UIColor (red: 49/255, green: 49/255, blue: 255/255, alpha: 1) // set text color
messageLabel.font = UIFont.systemFont(ofSize: 25) // set text size
messageLabel.backgroundColor = UIColor(red: 0, green: 1, blue: 0, alpha: 0.7) // set label background color
messageLabel.layer.cornerRadius = 20 // make a chamfer
messageLabel.clipsToBounds = true // clip the boundary
//messageLabel.transform = CGAffineTransform (rotationAngle: .pi/2*0.35)
//ironManImageView.addSubview (messageLabel)

ironManImageView.transform = CGAffineTransform (rotationAngle: .pi/2*0.3) // rotate the image
let spaceImage = UIImage (named: "outer_space.jpeg") //load space image
let spaceImageView = UIImageView(image: spaceImage) // creat imageView of space image
spaceImageView.addSubview(ironManImageView) // add ironMan as Space subView
spaceImageView.addSubview(messageLabel) // add Label as Space subView
spaceImageView.layer.borderWidth = 25 // set border width
spaceImageView.layer.borderColor = CGColor (red: 0, green: 0.5, blue: 0.5, alpha: 1) // set border color
spaceImageView.layer.cornerRadius = 50 // set shamfer
spaceImageView.clipsToBounds = true // clip the boundary

//var i = Int()
for i in 0...7 { // using loop to add emoji on the top of space image
let starLabel = UILabel (frame: CGRect (x: 50, y: 50+i*120, width: 60, height: 30))
starLabel.text = "🌟💫"
starLabel.font = UIFont.systemFont(ofSize: 25)
starLabel.transform = CGAffineTransform (rotationAngle: .pi/180 + CGFloat(i*40))
spaceImageView.addSubview (starLabel)
}

for i in 0...7 { // using loop to add emoji on the bottom of space image
let starLabel = UILabel (frame: CGRect (x: 900, y: 50+i*120, width: 60, height: 30))
starLabel.text = "🌟💫"
starLabel.font = UIFont.systemFont(ofSize: 25)
starLabel.transform = CGAffineTransform (rotationAngle: .pi/180 + CGFloat(i*40))
spaceImageView.addSubview (starLabel)
}

for i in 0...5 { // using loop to add emoji on the left of space image
let starLabel = UILabel (frame: CGRect (x: 170+i*120, y: 50, width: 60, height: 30))
starLabel.text = "🌟💫"
starLabel.font = UIFont.systemFont(ofSize: 25)
starLabel.transform = CGAffineTransform (rotationAngle: .pi/180 + CGFloat(i*40))
spaceImageView.addSubview (starLabel)
}

for i in 0...5 { // using loop to add emoji on the right of space image
let starLabel = UILabel (frame: CGRect (x: 170+i*120, y: 900, width: 60, height: 30))
starLabel.text = "🌟💫"
starLabel.font = UIFont.systemFont(ofSize: 25)
starLabel.transform = CGAffineTransform (rotationAngle: .pi/180 + CGFloat(i*40))
spaceImageView.addSubview (starLabel)
}
spaceImageView

--

--

ChengWen Lee
彼得潘的 Swift iOS / Flutter App 開發教室

After worked in office for 22 years, it is time to know the real word. I would like to be a Digital Nomad (Working everywhere) and on the way now~~~