Goddess Gallery App (Swift1.2)

Source: Internet
Author: User
Tags uikit

This app is a combination of storyboard+code, the main focus is:

1.segue Pass picture values.

In 2.Autolayout, you can use the lower-right triangle notation to use the Add Missing constraints to approximate the constraints to accommodate different screen sizes.

3. Upper column editor, Embed in, Navigation Controller or tab Bar controller.

4. Realize the sharing function.

5. Note that the modal type for segue is changed to the push type when designing the navigation controller Interface for storyboard.

6. Press and hold command to click on a controller control code to display its method class.

Storyboard Design Interface:

Directory structure:

Viewcontroller.swift File Code:

1 Import UIKit2 class Viewcontroller:uiviewcontroller {3 4 @IBOutlet weak var beautypicker:uipickerview!5 Let beauties = ["Fan Bingbing", "Li Bingbing", "Faye Wong", "Yang Mi", "Zhou Xun"]6 override func Viewdidload () {7 super.viewdidload ()8 Beautypicker.datasource = Self9 beautypicker.delegate = SelfTen     } One override func didreceivememorywarning () { A super.didreceivememorywarning () - //Dispose of any resources, can be recreated. -     } the      - override func Prepareforsegue (Segue:uistoryboardsegue, sender:anyobject?) { - if Segue.identifier = = "Gotogallery" { - Let index = beautypicker.selectedrowincomponent (0) + var imagename:string? - Switch index{ + Case 0: A imageName = "Fanbingbing" at Case 1: - imageName = "Libingbing" - Case 2: - imageName = "Wangfei" - Case 3: - imageName = "Yangmi" in Case 4: - imageName = "Zhouxun" to Default: + ImageName = Nil -                  the             } * var vc = Segue.destinationviewcontroller as! Gallerycontroller $ vc.imagename = ImageNamePanax Notoginseng         } -     } the}

View.swift (additional extension files for Viewcontroller.swift):

1 Import UIKit2 3 extension viewcontroller:uipickerviewdatasource{4 //Returns the number of ' columns ' to display.5 func Numberofcomponentsinpickerview (pickerview:uipickerview), int{6 return 17     }8 //Returns the # of rows in each component.9 func Pickerview (Pickerview:uipickerview, Numberofrowsincomponent component:int), int{Ten return Beauties.count One     } A } - extension viewcontroller:uipickerviewdelegate{ - func Pickerview (Pickerview:uipickerview, Titleforrow row:int, Forcomponent component:int), String! { the return Beauties[row] -     } -}

Gallerycontroller.swift File Code:

1 Import UIKit 2 import social 3 4 class Gallerycontroller:uiviewcontroller {5 var imagename:string?6     7 @IBOutlet weak var beautyimage:uiimageview!8 override func Viewdidload () {9 super.viewdidload ()Ten /*if (imageName! = nil) { One beautyimage.image = UIImage (named:imagename!) Before modification A         }*/ -          - if let name = imageName { the beautyimage.image = UIImage (named:name) - Switch name{ - Case "fanbingbing": - navigationitem.title = "Fan Bingbing" + Case "libingbing": - navigationitem.title = "Li Bingbing" + Case "Wangfei": A navigationitem.title = "Faye Wong" at Case "Yangmi": - navigationitem.title = "Yang mi" - Case "Zhouxun": - navigationitem.title = "Zhou Xun" - Default: - Navigationitem.title = "Goddess Gallery" in             } -         } to     } + override func didreceivememorywarning () { - super.didreceivememorywarning () the //Dispose of any resources, can be recreated. *     } $      PNS /share button  @IBAction func sharetapped (sender:anyobject) {  var Controller:slcomposeviewcontroller = Slcomposeviewcontroller (Forservicetype:slservicetypetencentweibo)  Controller.setinitialtext ("Play the Goddess Gallery app together, on GitHub")  Controller.addima GE (beautyimage.image)  self.presentviewcontroller (Controller, Animated:true, completion:n IL)    -}

Koreanviewcontroller File Code:

1 Import UIKit 2 import social 3 class Koreanviewcontroller:uiviewcontroller {4 @IBOutlet weak var beautyimage:uiimageview!5 override func Viewdidload () {6 super.viewdidload ()7     }8 override func didreceivememorywarning () {9 super.didreceivememorywarning ()Ten //Dispose of any resources, can be recreated. One     } A //facebook Share - @IBAction func facebootapped (sender:anyobject) { - var controller:slcomposeviewcontroller = Slcomposeviewcontroller (forservicetype:slservicetypefacebook) the Controller.setinitialtext ("Play the Goddess Gallery app together, on GitHub") - controller.addimage (beautyimage.image) - Self.presentviewcontroller (Controller, Animated:true, Completion:nil) -     } + //twitter Share - @IBAction func twittertapped (sender:anyobject) { + var controller:slcomposeviewcontroller = Slcomposeviewcontroller (forservicetype:slservicetypetwitter) A Controller.setinitialtext ("Play the Goddess Gallery app together, on GitHub") at controller.addimage (beautyimage.image) - Self.presentviewcontroller (Controller, Animated:true, Completion:nil) -     } - //Weibo sharing - @IBAction func weibotapped (sender:anyobject) { - var controller:slcomposeviewcontroller = Slcomposeviewcontroller (Forservicetype:slservicetypesinaweibo) in Controller.setinitialtext ("Play the Goddess Gallery app together, on GitHub") - controller.addimage (beautyimage.image) to Self.presentviewcontroller (Controller, Animated:true, Completion:nil) +     } -}

Operation Result:

Goddess Gallery App (Swift1.2)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.