DYNAMIC LABEL
open viewcontroller.swift and paste below code
//
// ViewController.swift
// FirstSwiftApp
//
// Created by Divakar Singh on 2/27/17.
// Copyright (c) 2017 Divakar Singh. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
// Declare instance variable
var label1 : UILabel!
var label2 : UILabel!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
// create the UI
label1 = UILabel()
label1.text = "First dynamic label"
label1.textColor = UIColor.greenColor()
label1.backgroundColor = UIColor.grayColor()
label1.textAlignment = NSTextAlignment.Right
//label1.textAlignment = .Right
label1.font = UIFont(name: "verdana", size: 16)
// or shorter way
//label1.font = UIFont.systemFontOfSize(20)
label1.highlighted = true
label1.highlightedTextColor = UIColor.orangeColor()
label1.layer.shadowOffset = CGSize(width: 3, height: 3)
label1.layer.shadowOpacity = 0.7
label1.layer.shadowRadius = 2
label1.sizeToFit()
label1.center = CGPoint(x: 150, y: 100)
view.addSubview(label1)
label2 = UILabel()
label2.frame = CGRect(x: 150, y: 100, width: 200, height: 50)
label2.text = "Second dynamic bold label,Second dynamic bold label,Second dynamic bold label"
label2.textColor = UIColor(red: 88.0/255.0, green: 152.0/255.0, blue: 222.0/255.0, alpha: 1)
label2.font = UIFont.boldSystemFontOfSize(20)
label2.numberOfLines = 3
label2.sizeToFit()
view.addSubview(label2)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
No comments:
Post a Comment