iT邦幫忙

2018 iT 邦幫忙鐵人賽
DAY 18
0
 @IBOutlet weak var mainScroll: UIScrollView! 
    
    var imageArray = [UIImage]()
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        imageArray = [#imageLiteral(resourceName: "Screen Shot 2018-01-06 at 20.22.59"), #imageLiteral(resourceName: "Screen Shot 2018-01-05 at 15.51.00"), #imageLiteral(resourceName: "Screen Shot 2018-01-05 at 15.50.46")]
        
        for images in 0 ..< imageArray.count {         
            let imageView = UIImageView()   //put our images into imageView
            imageView.image = imageArray[images]    
            //create an imageView for each iamge in imageArray
            //and then put the images into imageView one by one
            mainScroll.addSubview(imageView)   //add this imageView into our mainScroll
            
            let xPosition = self.view.frame.width * CGFloat(images)  
            //set the starting x for the whole content
            imageView.frame = CGRect(x: xPosition, y: 0, width: self.mainScroll.frame.width, height: self.mainScroll.frame.height) 
            //position our imageView
            
            mainScroll.contentSize.width = mainScroll.frame.width * CGFloat(images + 1)
            //calculate the width of our contentSize for mainScroll
    
            view.addSubview(mainScroll)
            //and finally, add this scrollView to our mainView
        }
    }

上一篇
DAY 17: APP 規劃細節 - functional map, and more
下一篇
DAY 19: 100 % 零基礎的 Firebase
系列文
Swift 學習目標 -- 30 天送審第一支APP33
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言