Guest User

Untitled

a guest
Aug 19th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 KB | None | 0 0
  1. import UIKit
  2.  
  3. let image = UIImage(named: "love.png") //指定love圖片
  4. let loveImageView = UIImageView(image: image) //型別宣告
  5. let colorfulImageView = UIImageView(frame: loveImageView.frame) //指定colorful圖案並告知和love同範圍
  6.  
  7. colorfulImageView.image = UIImage (named: "colorful.jpg") //指定colorful圖片
  8. colorfulImageView.addSubview(loveImageView) //幫colorful加上love圖層
  9.  
  10. loveImageView.backgroundColor = UIColor(red: 1, green: 0, blue: 0, alpha: 0.6) //指定背景色與透明度
  11.  
  12.  
  13. colorfulImageView
  14.  
  15.  
  16.  
  17.  
  18. //寫出臉
  19. var rect = CGRect(x: 0, y: 0, width: 200, height: 200) //設定rect範圍
  20. let faceView = UIView(frame: rect)
  21. faceView.backgroundColor = UIColor(red: 1, green: 0.8431, blue: 0.2275, alpha: 1.0) // #ffd73a
  22. faceView.layer.cornerRadius = 100
  23. faceView.clipsToBounds = true
  24.  
  25. //寫出眼睛1
  26.  
  27. let rectEyesOne = CGRect(x:65, y:60, width:20, height:20)
  28. let eyesOneView = UIView(frame: rectEyesOne)
  29.  
  30. eyesOneView.backgroundColor = UIColor(red: 0.1882, green: 0.1882, blue: 0.1882, alpha: 1.0) // #303030
  31.  
  32. //寫出眼睛2
  33. let rectEyesTwo = CGRect(x:120, y:60, width:20, height:20)
  34. let eyesTwoView = UIView(frame: rectEyesTwo)
  35.  
  36. eyesTwoView.backgroundColor = UIColor(red: 0.1882, green: 0.1882, blue: 0.1882, alpha: 1.0) // #303030
  37.  
  38. //寫出圓角
  39.  
  40. eyesOneView.layer.cornerRadius = 10
  41. eyesOneView.clipsToBounds = true
  42.  
  43. eyesTwoView.layer.cornerRadius = 10
  44. eyesTwoView.clipsToBounds = true
  45.  
  46. //寫出嘴巴的圓型弧度
  47.  
  48. var smileRect = CGRect(x:0, y:-50, width:100, height:100)
  49. let smileView = UIView(frame: smileRect)
  50. smileView.layer.borderWidth = 10
  51. smileView.layer.borderColor = UIColor(red: 0.1882, green: 0.1882, blue: 0.1882, alpha: 1.0).cgColor // #303030
  52. smileView.layer.cornerRadius = 50
  53. smileView.clipsToBounds = true
  54.  
  55. //寫出一個長方形顏色
  56. rect = CGRect(x:50, y:110, width:100, height:50)
  57. let smileBackegroundView = UIView(frame: rect)
  58. smileBackegroundView.backgroundColor = UIColor(red: 1, green: 0.8431, blue: 0.2275, alpha: 1.0) // #ffd73a
  59. smileBackegroundView.addSubview(smileView)
  60. smileBackegroundView.clipsToBounds = true
  61.  
  62. //全都合一起
  63. faceView.addSubview(eyesTwoView)
  64. faceView.addSubview(eyesOneView)
  65. faceView.addSubview(smileBackegroundView)
Add Comment
Please, Sign In to add comment