platform : ios, '9.0'
use_frameworks!
target 'DemoApp' do
source 'https://github.com/CocoaPods/Specs.git'
pod 'XLActionController'
pod 'XLActionController/Periscope'
pod 'XLActionController/Skype'
pod 'XLActionController/Spotify'
pod 'XLActionController/Tweetbot'
pod 'XLActionController/Twitter'
pod 'XLActionController/Youtube'
end
0. 测试UI
import UIKit
import XLActionController
class ViewController : UIViewController {
override func viewDidLoad ( ) {
super . viewDidLoad ( )
let button = UIButton ( frame: CGRect ( x: 20 , y: 300 , width: 374 , height: 40 ) )
button. backgroundColor = UIColor . orange
button. titleLabel? . font = . systemFont ( ofSize: 24 )
button. setTitle ( "Show me the XLActionController" , for : . normal)
button. addTarget ( self , action: #selector ( yeBtn) ,
for : . touchUpInside)
self . view. addSubview ( button)
self . view. backgroundColor = UIColor . orange
}
@objc func yeBtn ( ) {
yeTye6skypeActionController ( )
}
}
1. 风格一
func yeTye1TweetbotActionController ( ) {
let actionController = TweetbotActionController ( )
actionController. addAction ( Action ( "View Details" , style: . default , handler: { action in
print ( "---点击了该Btn,表单消失后才执行此闭包,View Details--" )
} ) )
actionController. addAction ( Action ( "View Retweets" , style: . default , handler: { action in
print ( "View Retweets" )
} ) )
actionController. addAction ( Action ( "View in Favstar" , style: . default , handler: { action in
print ( "View in Favstar" )
} ) )
actionController. addAction ( Action ( "Translate" , style: . default , executeImmediatelyOnTouch: true , handler: { action in
print ( "---被点击后,立即执行此闭包,(不用等表单消失),View Translate--" )
} ) )
actionController. addSection ( Section ( ) )
actionController. addAction ( Action ( "Cancel" , style: . cancel, handler: nil ) )
present ( actionController, animated: true , completion: nil )
}
2. 风格二
func yeTye2TwitterActionController ( ) {
let actionSheet = TwitterActionController ( )
actionSheet. headerData = "Accounts"
actionSheet. addAction ( Action ( ActionData ( title: "Xmartlabs" , subtitle: "@xmartlabs" , image: UIImage ( named: "tw-xmartlabs" ) ! ) , style: . default , handler: { action in
print ( "@xmartlabs" )
} ) )
actionSheet. addAction ( Action ( ActionData ( title: "Miguel" , subtitle: "@remer88" , image: UIImage ( named: "tw-remer" ) ! ) , style: . default , handler: { action in
print ( "@remer88" )
} ) )
present ( actionSheet, animated: true , completion: nil )
}
3. 风格三
func yeTye3YoutubeActionController ( ) {
let actionController = YoutubeActionController ( )
actionController. addAction ( Action ( ActionData ( title: "Add to Watch Later" , image: UIImage ( named: "yt-add-to-watch-later-icon" ) ! ) , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( ActionData ( title: "Add to Playlist..." , image: UIImage ( named: "yt-add-to-playlist-icon" ) ! ) , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( ActionData ( title: "Share..." , image: UIImage ( named: "yt-share-icon" ) ! ) , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( ActionData ( title: "Cancel" , image: UIImage ( named: "yt-cancel-icon" ) ! ) , style: . cancel, handler: nil ) )
present ( actionController, animated: true , completion: nil )
}
4. 风格四
func yeTye4periscopeActionController ( ) {
let actionController = PeriscopeActionController ( )
actionController. headerData = "Are you sure you want to block?"
actionController. addAction ( Action ( "Block user" , style: . destructive, handler: { action in
} ) )
actionController. addSection ( PeriscopeSection ( ) )
actionController. addAction ( Action ( "Cancel" , style: . cancel, handler: { action in
} ) )
present ( actionController, animated: true , completion: nil )
}
5. 风格五
func yeTye5spotifyActionController ( ) {
let actionController = SpotifyActionController ( )
actionController. headerData = SpotifyHeaderData ( title: "The Fast And The Furious Soundtrack Collection" , subtitle: "Various Artists" , image: UIImage ( named: "sp-header-icon" ) ! )
actionController. addAction ( Action ( ActionData ( title: "Save Full Album" , image: UIImage ( named: "sp-add-icon" ) ! ) , style: . default , handler: { action in } ) )
actionController. addAction ( Action ( ActionData ( title: "Remove" , image: UIImage ( named: "sp-remove-icon" ) ! ) , style: . default , handler: { action in } ) )
actionController. addAction ( Action ( ActionData ( title: "Share" , image: UIImage ( named: "sp-share-icon" ) ! ) , style: . default , handler: { action in } ) )
actionController. addAction ( Action ( ActionData ( title: "Go to Album" , image: UIImage ( named: "sp-view-album-icon" ) ! ) , style: . default , handler: { action in } ) )
actionController. addAction ( Action ( ActionData ( title: "Start radio" , image: UIImage ( named: "sp-radio-icon" ) ! ) , style: . default , handler: { action in } ) )
present ( actionController, animated: true , completion: nil )
}
6. 风格六
func yeTye6skypeActionController ( ) {
let actionController = SkypeActionController ( )
actionController. addAction ( Action ( "Take photo" , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( "Choose existing photo" , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( "Remove profile picture" , style: . default , handler: { action in
} ) )
actionController. addAction ( Action ( "Cancel" , style: . cancel, handler: nil ) )
present ( actionController, animated: true , completion: nil )
}