ios - How to make image weight and height fill screen in Swift Xcode? -


i found code make slide in swift, cant find, how make image fill whole screen. help?

here screenshot of slider, , see anchors placed on show you, whole screen.

enter image description here

and here code of it;

import uikit class onboardingcontroller: uiviewcontroller, uiscrollviewdelegate {     let backgroundcolor = uicolor(red: 241.0/255.0, green: 196.0/255.0, blue: 15.0/255.0, alpha: 1.0)     let slides = [         [ "image": "book4page1.png"],         [ "image": "book4page2.png"],         [ "image": "book4page3.png"],     ]     let screen: cgrect = uiscreen.mainscreen().bounds     var scroll: uiscrollview?     var dots: uipagecontrol?     override func viewdidload() {         super.viewdidload()         view.backgroundcolor = backgroundcolor         scroll = uiscrollview(frame: cgrect(x: 0.0, y: 0.0, width: screen.width, height: screen.height * 0.9))         scroll?.showshorizontalscrollindicator = false         scroll?.showsverticalscrollindicator = false         scroll?.pagingenabled = true         view.addsubview(scroll!)         if (slides.count > 1) {             dots = uipagecontrol(frame: cgrect(x: 0.0, y: screen.height * 0.875, width: screen.width, height: screen.height * 0.05))             dots?.numberofpages = slides.count             view.addsubview(dots!)         }         var = 0; < slides.count; ++i {             if let image = uiimage(named: slides[i]["image"]!) {                 let imageview: uiimageview = uiimageview(frame: getframe(image.size.width, ih: image.size.height, slide: i, offset: screen.height * 0.15))                 imageview.image = image                 scroll?.addsubview(imageview)             }             if let text = slides[i]["text"] {                 let textview = uitextview(frame: cgrect(x: screen.width * 0.05 + cgfloat(i) * screen.width, y: screen.height * 0.745, width: screen.width * 0.9, height: 100.0))                 textview.text = text                 textview.editable = false                 textview.selectable = false                 textview.textalignment = nstextalignment.center                 textview.font = uifont.systemfontofsize(20, weight: 0)                 textview.textcolor = uicolor.whitecolor()                 textview.backgroundcolor = uicolor.clearcolor()                 scroll?.addsubview(textview)             }         }         scroll?.contentsize = cgsizemake(cgfloat(int(screen.width) *  slides.count), screen.height * 0.5)         scroll?.delegate = self         dots?.addtarget(self, action: selector("swipe:"), forcontrolevents: uicontrolevents.valuechanged)         let closebutton = uibutton()         closebutton.frame = cgrect(x: screen.width - 70, y: 20, width: 60, height: 60)         closebutton.settitle("skip", forstate: .normal)         closebutton.settitlecolor(uicolor(red: 0.0/255.0, green: 0.0/255.0, blue: 0.0/255.0, alpha: 0.5), forstate: .normal)         closebutton.titlelabel!.font =  uifont.systemfontofsize(16)         closebutton.addtarget(self, action: "pressed:", forcontrolevents: .touchupinside)         view.addsubview(closebutton)     }     func pressed(sender: uibutton!) {         self.dismissviewcontrolleranimated(true) { () -> void in         }     }     override func didreceivememorywarning() {         super.didreceivememorywarning()     }     func getframe (iw: cgfloat, ih: cgfloat, slide: int, offset: cgfloat) -> cgrect {         let mh: cgfloat = screen.height * 0.50         let mw: cgfloat = screen.width         var h: cgfloat         var w: cgfloat         let r = iw / ih         if (r <= 1) {             h = min(mh, ih)             w = h * r         } else {             w = min(mw, iw)             h = w / r         }         return cgrectmake(             max(0, (mw - w) / 2) + cgfloat(slide) * screen.width,             max(0, (mh - h) / 2) + offset,             w,             h         )     }     func swipe(sender: anyobject) -> () {         if let scrollview = scroll {             let x = cgfloat(dots!.currentpage) * scrollview.frame.size.width             scroll?.setcontentoffset(cgpointmake(x, 0), animated: true)         }     }     func scrollviewdidenddecelerating(scrollview: uiscrollview) -> () {         let pagenumber = round(scrollview.contentoffset.x / scrollview.frame.size.width)         dots!.currentpage = int(pagenumber)     }     override func preferredstatusbarstyle() -> uistatusbarstyle {         return uistatusbarstyle.lightcontent     } } 

on imageview set imageview.contentmode = uiviewcontentmode.scaleaspectfit


Comments

Popular posts from this blog

java - Jasper subreport showing only one entry from the JSON data source when embedded in the Title band -

serialization - Convert Any type in scala to Array[Byte] and back -

SonarQube Plugin for Jenkins does not find SonarQube Scanner executable -