2 // FadeoutTextField.swift
5 // Created by Hori,Masaki on 2017/09/16.
6 // Copyright © 2017年 Hori,Masaki. All rights reserved.
11 class FadeoutTextField: NSTextField {
13 var middle1: CGFloat = 0.8
14 var middle2: CGFloat = 1.0
16 private var maskImage: CGImage? {
18 if !isCharacterProtrude() {
23 if let image = cachMaskImage {
28 cachMaskImage = maskImage(middle1: middle1, middle2: middle2)
33 private var cachMaskImage: CGImage?
35 override func draw(_ dirtyRect: NSRect) {
37 guard let context = NSGraphicsContext.current?.cgContext else {
39 fatalError("Con not get current CGContext")
43 maskImage.map { context.clip(to: bounds, mask: $0) }
47 context.restoreGState()
50 override func resizeSubviews(withOldSize oldSize: NSSize) {
54 super.resizeSubviews(withOldSize: oldSize)