     private func initialize(with ghostColor: UIColor) {
         self.ghostColor = ghostColor
     }
+    
+    private func updateImageColor() {
+        self.imageView?.tintColor = adjustsImageWithGhostColor ? self.ghostColor : nil
+        if self.currentImage != nil {
+            let states: [UIControlState] = [.normal, .highlighted, .disabled]
+            for state in states {
+                if let image = self.image(for: state) {
+                    if self.adjustsImageWithGhostColor {
+                        // 这里的image不用做renderingMode的处理，而是放到重写的setImage:forState里去做
+                        self.setImage(image, for: state)
+                    } else {
+                        // 如果不需要用template的模式渲染，并且之前是使用template的，则把renderingMode改回Original
+                        self.setImage(image.withRenderingMode(.alwaysOriginal), for: state)
+                    }
+                }
+            }
+        }
+    }
+    
+    override func setImage(_ image: UIImage?, for state: UIControlState) {
+        var image = image
+        if self.adjustsImageWithGhostColor {
+            image = image?.withRenderingMode(.alwaysTemplate)
+        }
+        super.setImage(image, for: state)
+    }
+    
+    override func layoutSublayers(of layer: CALayer) {
+        super.layoutSublayers(of: layer)
+        if self.cornerRadius != QMUIGhostButtonCornerRadiusAdjustsBounds {
+            self.layer.cornerRadius = self.cornerRadius
+        } else {
+            self.layer.cornerRadius = flat(self.bounds.height / 2)
+        }
+    }
 }
+
+// TODO @implementation QMUIGhostButton (UIAppearance)
+
 
 /**
  *  用于 `QMUIFillButton.cornerRadius` 属性，当 `cornerRadius` 为 `QMUIFillButtonCornerRadiusAdjustsBounds` 时，`QMUIFillButton` 会在高度变化时自动调整 `cornerRadius`，使其始终保持为高度的 1/2。
  */
-public let QMUIFillButtonCornerRadiusAdjustsBounds = -1
+public let QMUIFillButtonCornerRadiusAdjustsBounds: CGFloat = -1
 
 /**
  *  QMUIFillButton
  *  实心填充颜色的按钮，支持预定义的几个色值
  */
-/*
- class QMUIFillButton: QMUIButton {
- // TODO: - UI_APPEARANCE_Selector?的宏没有写
- @IBInspectable var fillColor: UIColor               // 默认为 FillButtonColorBlue
- @IBInspectable var titleTextColor: UIColor          // 默认为 UIColorWhite
- @IBInspectable var cornerRadius: CGFloat              // 默认为 QMUIFillButtonCornerRadiusAdjustsBounds，也即固定保持按钮高度的一半。
-
- /**
-  *  控制按钮里面的图片是否也要跟随 `titleTextColor` 一起变化，默认为 `NO`
-  */
- var adjustsImageWithTitleTextColor: Bool
-
- init(with fillType: QMUIFillButtonColor) {
-
- }
-
- init(with fillType: QMUIFillButtonColor, frame: CGRect) {
-
- }
-
- init(with fillColor: UIColor, titleColor: UIColor) {
-
- }
-
- init(with fillColor: UIColor, titleColor: UIColor, frame: CGRect) {
-
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
- */
+
+class QMUIFillButton: QMUIButton {
+    @IBInspectable var fillColor: UIColor = .blue {               // 默认为 FillButtonColorBlue
+        didSet {
+            self.backgroundColor = fillColor
+        }
+    }
+    @IBInspectable var titleTextColor: UIColor = UIColorWhite {        // 默认为 UIColorWhite
+        didSet {
+            if adjustsImageWithTitleTextColor {
+                self.updateImageColor()
+            }
+        }
+    }
+    @IBInspectable var cornerRadius: CGFloat = QMUIFillButtonCornerRadiusAdjustsBounds / 2 {            // 默认为 QMUIFillButtonCornerRadiusAdjustsBounds，也即固定保持按钮高度的一半。
+        didSet {
+            self.setNeedsLayout()
+        }
+    }
+    /**
+     *  控制按钮里面的图片是否也要跟随 `titleTextColor` 一起变化，默认为 `NO`
+     */
+    var adjustsImageWithTitleTextColor: Bool = false {
+        didSet {
+            if adjustsImageWithTitleTextColor {
+                self.updateImageColor()
+            }
+        }
+    }
+    
+    convenience init() {
+        self.init(with: .blue)
+    }
+    
+    override convenience init(frame: CGRect) {
+        self.init(with: .blue, frame: frame)
+    }
+    
+    convenience init(with fillType: QMUIFillButtonColor) {
+        self.init(with: .blue, frame: .zero)
+    }
+    
+    convenience init(with fillType: QMUIFillButtonColor, frame: CGRect) {
+        var fillColor = FillButtonColorBlue
+        let textColor = UIColorWhite
+        switch fillType {
+        case .blue:
+            fillColor = FillButtonColorBlue
+        case .red:
+            fillColor = FillButtonColorRed
+        case .green:
+            fillColor = FillButtonColorGreen
+        case .gray:
+            fillColor = FillButtonColorGray
+        case .white:
+            fillColor = FillButtonColorWhite
+        default:
+            break
+        }
+        
+        self.init(with: fillColor ?? .blue,titleTextColor: textColor, frame: frame)
+    }
+    
+    convenience init(with fillColor: UIColor, titleTextColor: UIColor) {
+        self.init(with: fillColor,titleTextColor: titleTextColor, frame: .zero)
+    }
+    
+    init(with fillColor: UIColor, titleTextColor: UIColor, frame: CGRect) {
+        super.init(frame: frame)
+        
+        self.fillColor = fillColor
+        self.titleTextColor = titleTextColor
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        super.init(coder: aDecoder)
+        self.fillColor = FillButtonColorBlue ?? .blue
+        self.titleTextColor = UIColorWhite
+    }
+    
+    override func setImage(_ image: UIImage?, for state: UIControlState) {
+        var image = image
+        if adjustsImageWithTitleTextColor {
+            image = image?.withRenderingMode(.alwaysTemplate)
+        }
+        super.setImage(image, for: state)
+    }
+    
+    
+    
+    private func updateImageColor() {
+        self.imageView?.tintColor = adjustsImageWithTitleTextColor ? self.titleTextColor : nil
+        if self.currentImage != nil {
+            let states: [UIControlState] = [.normal, .highlighted, .disabled]
+            for state in states {
+                if let image = self.image(for: state) {
+                    if self.adjustsImageWithTitleTextColor {
+                        // 这里的image不用做renderingMode的处理，而是放到重写的setImage:forState里去做
+                        self.setImage(image, for: state)
+                    } else {
+                        // 如果不需要用template的模式渲染，并且之前是使用template的，则把renderingMode改回Original
+                        self.setImage(image.withRenderingMode(.alwaysOriginal), for: state)
+                    }
+                }
+            }
+        }
+    }
+    
+    override func layoutSublayers(of layer: CALayer) {
+        super.layoutSublayers(of: layer)
+        if self.cornerRadius != QMUIGhostButtonCornerRadiusAdjustsBounds {
+            self.layer.cornerRadius = self.cornerRadius
+        } else {
+            self.layer.cornerRadius = flat(self.bounds.height / 2)
+        }
+    }
+}
+


    /// 下划线的位置是基于 titleLabel 的位置来计算的，默认x、width均和titleLabel一致，而可以通过这个属性来调整下划线的偏移值。默认为UIEdgeInsetsZero。
    @IBInspectable var underlineInsets: UIEdgeInsets = .zero

    override init(frame: CGRect) {
        super.init(frame: frame)

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
    }
    
    // 修复系统的UIBarButtonItem里的图片无法跟着tintColor走
    override func setImage(_ image: UIImage?, for state: UIControlState) {
        if var image = image {
            image = image.withRenderingMode(.alwaysTemplate)
        }
        
        super.setImage(image, for: state)
    }
    
    // 自定义nav按钮，需要根据这个来修改title的三态颜色
    override func tintColorDidChange() {
        super.tintColorDidChange()
        
        self.setTitleColor(self.tintColor, for: .normal)
        self.setTitleColor(self.tintColor.withAlphaComponent(NavBarHighlightedAlpha), for: .highlighted)
        self.setTitleColor(self.tintColor.withAlphaComponent(NavBarDisabledAlpha), for: .disabled)
    }
    
    override var alignmentRectInsets: UIEdgeInsets {
        var insets = super.alignmentRectInsets

        if buttonPosition == .none || self.useForBarButtonItem {
            return insets
        }

        if case .left = buttonPosition {
            // 正值表示往左偏移
            if case .image = type {
                insets.setLeft(11)
            } else {
                insets.setLeft(8)
            }
        } else if case .right = buttonPosition {
            // 正值表示往右偏移
            if case .image = type {
                insets.setRight(11)
            } else {
                insets.setRight(8)
            }
        }
        
        let isBackOrImageType = self.type == .back || self.type == .image
        if isBackOrImageType {
            insets.setTop(PixelOne)
        } else {
            insets.setTop(1)
        }

        return insets
    }
    
    private func renderButtonStyle() {
        let font = NavBarButtonFont

        self.titleLabel?.font = font
        self.titleLabel?.backgroundColor = UIColorClear
        self.titleLabel?.lineBreakMode = .byTruncatingTail
        self.contentMode = .center
        self.contentHorizontalAlignment = .center
        self.contentVerticalAlignment = .center
        self.adjustsImageWhenHighlighted = false
        self.adjustsImageWhenDisabled = false
        
        switch self.type {
        case .normal, .image:
            return
        case .bold:
            self.titleLabel?.font = NavBarButtonFontBold
        case .back:
            self.contentHorizontalAlignment = .left
            let backIndicatorImage = NavBarBackIndicatorImage
            self.setImage(backIndicatorImage, for: .normal)
            self.setImage(backIndicatorImage?.qmui_imageWith(alpha: NavBarHighlightedAlpha), for: .highlighted)
            self.setImage(backIndicatorImage?.qmui_imageWith(alpha: NavBarDisabledAlpha), for: .disabled)
        default:
            break
        }
    }

    /**
     *  创建一个 type 为 QMUINavigationButtonTypeBack 的 button 并作为 customView 用于生成一个 UIBarButtonItem，返回按钮的图片由配置表里的宏 NavBarBackIndicatorImage 决定。
