Skip to content

Instantly share code, notes, and snippets.

@joeangel
Created June 5, 2015 07:34
Show Gist options
  • Save joeangel/132cbd0edb56baefe9ad to your computer and use it in GitHub Desktop.
Save joeangel/132cbd0edb56baefe9ad to your computer and use it in GitHub Desktop.
GradientViewController.swift
//
// GradientViewController.swift
// 透明至黑漸層
//
// Created by JoeAngel on 2015/06/05.
//
import UIKit
class Colors {
let colorTop = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 0.0).CGColor
let colorBottom = UIColor(red: 0/255.0, green: 0/255.0, blue: 0/255.0, alpha: 1.0).CGColor
let gl: CAGradientLayer
init() {
gl = CAGradientLayer()
gl.colors = [colorTop, colorBottom]
gl.locations = [0.0, 1.0]
}
}
class GradientViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
NSLog("<%@:%d %@>", __FILE__.lastPathComponent, __LINE__, __FUNCTION__)
var backgroundLayer = Colors().gl
println(bannerScrollView.frame)
println(bannerScrollView.contentSize)
backgroundLayer.frame = CGRectMake(imageView.frame.minX, imageView.frame.minY, w, h)
self.view.layer.insertSublayer(backgroundLayer, atIndex: 999)
var nameLabel = UILabel(frame: CGRectMake(0, 0, 100, 30)
cpDiscriptionLabel.text = "相遇時,學著要;告別時,試著剛強"
cpDiscriptionLabel.textColor = UIColor.whiteColor()
self.view.addSubview(nameLabel)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
NSLog("<%@:%d %@>", __FILE__.lastPathComponent, __LINE__, __FUNCTION__)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment