본문 바로가기
Programming/ios

[swift를 이용한 ios 앱 개발] UILable을 이용하여 Text 넣기

by guru_k 2015. 12. 30.
728x90
반응형
프로젝트를 생성한 후 UILable 을 이용하여 Text를 추가

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import UIKit
 
class ViewController: UIViewController {
 
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
 
        
        // Get width, height Frame Size -- 프레임의 가로와 세로 사이즈
        var width : CGFloat = self.view.frame.size.width
        var height : CGFloat = self.view.frame.size.height
        
        // Title UILabel -- UILabel 생성 후 크기 조정
        var titleTxt = UILabel(frame: CGRectMake(0, height/2, width, height/6))
        // Text -- 텍스트 설정
        titleTxt.text = "Hello Swift"
        // Alignment
        titleTxt.textAlignment = NSTextAlignment.Center
        // Font
        titleTxt.font = UIFont(name: "System", size: 40)
        // Color
        titleTxt.textColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1)
        
        // Display
        self.view.addSubview(titleTxt)
        
    }
 
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
 
 
}
cs


CGRectMake 


파라메터를 입력받아 사각형을 만든다.


func CGRectMake(_ xCGFloat_ yCGFloat_ widthCGFloat_ heightCGFloat) -> CGRect


Parameter


x : x축 시작점

y : y축 시작점

width : 사각형의 가로 크기

height : 사각형의 세로 크기


참조 : 



-출력 결과 화면 




728x90
반응형

댓글