I think everyone is familiar with the ability to call system albums in IOS , but the Swift language call may not be very clear to many partners, after all, Swift is a new language, so the syntax and implementation may not be very clear, So today do a demo, we can do a reference.
//
Viewcontroller.swift
Ios
//
Created by Yue technology on 15/1/12.
Copyright (c) year BSY. All rights reserved.
//
Import UIKit
Class Viewcontroller:uiviewcontroller, uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate{
Override Func Viewdidload () {
Super.viewdidload ()
Create UIButton
var Button:uibutton = UIButton ()
Set Frame
var frame = CGRectMake (100, 60, 100, 60)
Button.frame = Frame
Set Font Color
Button.settitlecolor (Uicolor.redcolor (), ForState:UIControlState.Normal)
Set Font
Button.settitle (" point I have surprise ", ForState:UIControlState.Normal)
Add Method
Button.addtarget (Self, Action: "ButtonClick", ForControlEvents:UIControlEvents.TouchUpInside)
Add to Parent control
Self.view.addSubview (Button)
}
/**
Implementing the button method
*/
Func ButtonClick () {
var pick:uiimagepickercontroller = Uiimagepickercontroller ()
Pick.delegate = Self
Self.presentviewcontroller (pick, Animated:true, Completion:nil)
}
/**
Implementing Proxy Methods Uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate
*/
Func Imagepickercontroller (Picker:uiimagepickercontroller, didfinishpickingmediawithinfo info: [nsobject:anyobject ]) {
var Imageview:uiimageview = Uiimageview (frame:cgrectmake (0, 100, 320, 300))
Let Gotimage = Info[uiimagepickercontrolleroriginalimage] as UIImage
Imageview.image = Gotimage
Self.view.addSubview (ImageView)
println (info);
Self.dismissviewcontrolleranimated (True, Completion:nil);
}
/**
Implementing Proxy Methods Uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate
*/
Func Imagepickercontrollerdidcancel (Picker:uiimagepickercontroller) {
}
}
Swift development of the call system album