Created
October 5, 2014 23:16
-
-
Save baobao/b21ed041c3aa1ce44db1 to your computer and use it in GitHub Desktop.
Helloworld Swift
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
| // | |
| // ViewController.swift | |
| // helloworld-swift | |
| // | |
| // Created by Shunsuke Ohba on 2014/10/04. | |
| // Copyright (c) 2014年 Shunsuke Ohba. All rights reserved. | |
| // | |
| import UIKit | |
| class ViewController: UIViewController | |
| { | |
| override func viewDidLoad() | |
| { | |
| super.viewDidLoad() | |
| // Do any additional setup after loading the view, typically from a nib. | |
| // 全体サイズ 第1第2引数を0にすると、中心が座標となるこの場合(150,200) | |
| let myLabel:UILabel = UILabel(frame:CGRectMake(0, 0, 300, 400)) | |
| // layerの座標は150, 200を指す | |
| // デフォルトでこのような処理になることを肝に命じておこう | |
| print(myLabel.layer.position) | |
| myLabel.backgroundColor = UIColor.orangeColor() | |
| myLabel.text = "Hello world Swift" | |
| myLabel.layer.masksToBounds = true | |
| myLabel.textColor = UIColor.blackColor() | |
| // myLabel.x = 20 | |
| // myLabel.y = 10 | |
| // myLabel.position = CGPointMake (20, 10); | |
| myLabel.layer.position = CGPointMake(0, 0) | |
| myLabel.layer.anchorPoint = CGPointMake (0, 0) | |
| myLabel.angle = 30 | |
| // myLabel.xx = 0 | |
| self.view.addSubview(myLabel); | |
| } | |
| override func didReceiveMemoryWarning() { | |
| super.didReceiveMemoryWarning() | |
| // Dispose of any resources that can be recreated. | |
| } | |
| } | |
| extension UIView | |
| { | |
| var anchorPoint:CGPoint { | |
| get { | |
| return self.layer.anchorPoint | |
| } | |
| set { | |
| self.layer.anchorPoint = newValue | |
| } | |
| } | |
| var x:CGFloat { | |
| get { | |
| return self.layer.position.x; | |
| } | |
| set { | |
| self.layer.position.x = newValue | |
| } | |
| } | |
| var y:CGFloat { | |
| get { | |
| return self.layer.position.y; | |
| } | |
| set { | |
| self.layer.position.y = newValue | |
| } | |
| } | |
| var position:CGPoint { | |
| get { | |
| return self.layer.position; | |
| } | |
| set { | |
| self.layer.position = newValue; | |
| } | |
| } | |
| var angle:CGFloat { | |
| get{ | |
| return 0; | |
| } | |
| set { | |
| var rad = M_PI/180 | |
| var v = newValue * CGFloat(rad) | |
| self.transform = CGAffineTransformMakeRotation(v) | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment