Created
June 19, 2015 12:25
-
-
Save NoasProject/56858415b5e9a941e86c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| import Social | |
| class ViewController: UIViewController { | |
| var myComposeView : SLComposeViewController! | |
| var myTwitterButton: UIButton! | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| // Twitter用のUIButtonの生成. | |
| let hex: Int = 0x55ACEE | |
| let red = Double((hex & 0xFF0000) >> 16) / 255.0 | |
| let green = Double((hex & 0xFF00) >> 8) / 255.0 | |
| let blue = Double((hex & 0xFF)) / 255.0 | |
| var myColor: UIColor = UIColor( red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(1.0)) | |
| // ボタン. | |
| myTwitterButton = UIButton() | |
| myTwitterButton.frame = CGRectMake(0,0,100,100) | |
| myTwitterButton.backgroundColor = myColor | |
| myTwitterButton.layer.masksToBounds = true | |
| myTwitterButton.setTitle("Twitter", forState: UIControlState.Normal) | |
| myTwitterButton.titleLabel?.font = UIFont.systemFontOfSize(CGFloat(20)) | |
| myTwitterButton.setTitleColor(UIColor.whiteColor(), forState: UIControlState.Normal) | |
| myTwitterButton.layer.cornerRadius = 50.0 | |
| myTwitterButton.layer.position = CGPoint(x: self.view.frame.width/2, y:self.view.frame.height/2) | |
| myTwitterButton.tag = 1 | |
| myTwitterButton.addTarget(self, action: "onPostToTwitter:", forControlEvents: .TouchUpInside) | |
| myTwitterButton.setBackgroundImage(UIImage(name: "icon.png"), forState: UIControlState.Normal) | |
| // buttonをviewに追加. | |
| self.view.addSubview(myTwitterButton) | |
| } | |
| // ボタンイベント. | |
| func onPostToTwitter(sender : AnyObject) { | |
| // SLComposeViewControllerのインスタンス化. | |
| // ServiceTypeをTwitterに指定. | |
| myComposeView = SLComposeViewController(forServiceType: SLServiceTypeTwitter) | |
| // 投稿するテキストを指定. | |
| myComposeView.setInitialText("Twitter Test from Swift") | |
| // 投稿する画像を指定. | |
| myComposeView.addImage(UIImage(named: "oouchi.jpg")) | |
| // myComposeViewの画面遷移. | |
| self.presentViewController(myComposeView, animated: true, completion: nil) | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment