女神画廊App (Swift1.2)
2015-09-01 15:06
337 查看
这个App的是storyboard+code的结合,主要的重点是:
1.segue传递图片值。
2.Autolayout中可以使用右下角三角符号使用Add Missing Constraints进行大概约束,使之适应不同大小屏幕。
3.上边栏Editor -> Embed In -> Navigation Controller或者Tab Bar Controller。
4.实现分享功能。
5.注意storyboard设计Navigation Controller界面时关于segue的modal类型要改为push类型。
6.按住Command点击某个Controller控件代码可显示其方法类。
storyboard设计界面:
目录结构:
ViewController.swift文件代码:
View.swift (ViewController.swift的额外扩展文件):
GalleryController.swift文件代码:
KoreanViewController文件代码:
运行结果:
github地址:https://github.com/AbelSu131/BeautyGallery
1.segue传递图片值。
2.Autolayout中可以使用右下角三角符号使用Add Missing Constraints进行大概约束,使之适应不同大小屏幕。
3.上边栏Editor -> Embed In -> Navigation Controller或者Tab Bar Controller。
4.实现分享功能。
5.注意storyboard设计Navigation Controller界面时关于segue的modal类型要改为push类型。
6.按住Command点击某个Controller控件代码可显示其方法类。
storyboard设计界面:
目录结构:
ViewController.swift文件代码:
import UIKit class ViewController: UIViewController { @IBOutlet weak var beautyPicker: UIPickerView! let beauties = ["范冰冰","李冰冰","王菲","杨幂","周迅"] override func viewDidLoad() { super.viewDidLoad() beautyPicker.dataSource = self beautyPicker.delegate = self } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) { if segue.identifier == "GoToGallery"{ let index = beautyPicker.selectedRowInComponent(0) var imageName:String? switch index{ case 0: imageName = "fanbingbing" case 1: imageName = "libingbing" case 2: imageName = "wangfei" case 3: imageName = "yangmi" case 4: imageName = "zhouxun" default: imageName = nil } var vc = segue.destinationViewController as! GalleryController vc.imageName = imageName } } }
View.swift (ViewController.swift的额外扩展文件):
import UIKit extension ViewController:UIPickerViewDataSource{ // returns the number of 'columns' to display. func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int{ return 1 } // returns the # of rows in each component.. func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{ return beauties.count } } extension ViewController:UIPickerViewDelegate{ func pickerView(pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String!{ return beauties[row] } }
GalleryController.swift文件代码:
import UIKit import Social class GalleryController: UIViewController { var imageName:String? @IBOutlet weak var beautyImage: UIImageView! override func viewDidLoad() { super.viewDidLoad() /*if (imageName != nil){ beautyImage.image = UIImage(named: imageName!)//修改前 }*/ if let name = imageName { beautyImage.image = UIImage(named: name) switch name{ case "fanbingbing": navigationItem.title = "范冰冰" case "libingbing": navigationItem.title = "李冰冰" case "wangfei": navigationItem.title = "王菲" case "yangmi": navigationItem.title = "杨幂" case "zhouxun": navigationItem.title = "周迅" default: navigationItem.title = "女神画廊" } } } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //分享按钮 @IBAction func shareTapped(sender: AnyObject) { var controller: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTencentWeibo) controller.setInitialText("一起来玩女神画廊app吧,就在Github上") controller.addImage(beautyImage.image) self.presentViewController(controller, animated: true, completion: nil) } }
KoreanViewController文件代码:
import UIKit import Social class KoreanViewController: UIViewController { @IBOutlet weak var beautyImage: UIImageView! override func viewDidLoad() { super.viewDidLoad() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //facebook分享 @IBAction func facebooTapped(sender: AnyObject) { var controller: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook) controller.setInitialText("一起来玩女神画廊app吧,就在Github上") controller.addImage(beautyImage.image) self.presentViewController(controller, animated: true, completion: nil) } //twitter分享 @IBAction func twitterTapped(sender: AnyObject) { var controller: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeTwitter) controller.setInitialText("一起来玩女神画廊app吧,就在Github上") controller.addImage(beautyImage.image) self.presentViewController(controller, animated: true, completion: nil) } //微博分享 @IBAction func WeiboTapped(sender: AnyObject) { var controller: SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeSinaWeibo) controller.setInitialText("一起来玩女神画廊app吧,就在Github上") controller.addImage(beautyImage.image) self.presentViewController(controller, animated: true, completion: nil) } }
运行结果:
github地址:https://github.com/AbelSu131/BeautyGallery
相关文章推荐
- swift总结2
- 最老程序员创业开发实训5---Swift语言极速入门
- 相亲神器记录Swift1.2
- swift总结1
- swift自学注意点
- swift 中#pragma mark 表示方法
- swift详解之二十--------在xcode中使用git管理源代码,将代码提交到github
- swift 添加按钮
- swift - The Chain Responsibility pattern
- swift详解之十九--------------UITableView的基本操作(下拉刷新,新增删除,分组,检索等)
- IOS--Swift 01
- Swift UILabel 文字大小随着宽度调整
- Swift UILabel常用功能
- Swift子类初始化函数中调用父类初始化函数的正确位置
- swift 创建单例模式
- 【IOS-Swift】实战笔记——数据持久化之NSUserDefaults(本地轻量级数据存储)
- 【IOS-Swift】实战笔记——数据持久化之归档NSKeyedArchiver
- [iOS]#Swift#OC+Swift混编
- JAVA人学习ios swift(笔记)
- Swift2.0发布以来的历次主要更新