-
iOS) Scrollview Programmatically (코드로 작성)Programing Language/iOS(Swift) 2019. 11. 28. 20:31728x90반응형
예제 코드~
let scrollview : UIScrollView = { let sv = UIScrollView() sv.translatesAutoresizingMaskIntoConstraints = false //sv.backgroundColor = .black sv.isPagingEnabled = true //이걸해야지 한번 슬라이드할때마다 다음 화면으로 획 넘어감 return sv }() var images : [UIImage] = [#imageLiteral(resourceName: "IMG_0058"),#imageLiteral(resourceName: "IMG_0058"),#imageLiteral(resourceName: "IMG_0058")] //scrollview 크기조절은 내키는데로~~ func fitmeImages() { print(fitme_images_scrollview.frame.width) for i in 0..<images.count { let scroll_imageView = UIImageView() scroll_imageView.image = self.images[i] let xPosition = self.scrollview.frame.width * CGFloat(i) scroll_imageView.contentMode = .scaleAspectFit scroll_imageView.frame = CGRect(x: xPosition, y: 0, width: self.scrollview.frame.width, height: self.scrollview.frame.height) scroll_imageView.center = .init(x: self.scrollview.frame.width / 2 + xPosition, y: scrollview.frame.height / 2) scrollview.contentSize.width = scrollview.frame.width * CGFloat(i + 1) crollview.addSubview(scroll_imageView) } }
728x90반응형'Programing Language > iOS(Swift)' 카테고리의 다른 글
iOS) Disable “Dark Mode” in iOS 13 -swift (0) 2019.12.03 iOS ) CollectionView에 수평 스크롤 넣기 Programmatically (horizon) - swift (0) 2019.11.29 iOS ) 스크린에 상태 바 없애기(시간, 배터리잔량 등) (0) 2019.11.27 iOS ) 카운트 다운 메서드 (0) 2019.11.27 iOS ) Error: Could not build Objective-C module (0) 2019.11.27