I want to use LTMorphingLabel as a label in UILabel.
I created a new class but it doesn't work.

This is the code I wrote for that.

import UIKit

class MorphingButton: UIButton {
    override var titleLabel: LTMorphingLabel? {
        get {
            return self.titleLabel?
        }
    }

}

Does anyone know the way to overwrite it? Is it possible?

Here is the definition of UIButton.

import Foundation
import UIKit

//
//  UIButton.h
//  UIKit
//
//  Copyright (c) 2005-2014 Apple Inc. All rights reserved.
//

enum UIButtonType : Int {
    case Custom // no button type
    case System // standard system button

    case DetailDisclosure
    case InfoLight
    case InfoDark
    case ContactAdd
}

// Deprecated, use UIButtonTypeSystem instead

class UIButton : UIControl, NSCoding {

    class func buttonWithType(buttonType: UIButtonType) -> AnyObject

    var contentEdgeInsets: UIEdgeInsets // default is UIEdgeInsetsZero
    var titleEdgeInsets: UIEdgeInsets // default is UIEdgeInsetsZero
    var reversesTitleShadowWhenHighlighted: Bool // default is NO. if YES, shadow reverses to shift between engrave and emboss appearance
    var imageEdgeInsets: UIEdgeInsets // default is UIEdgeInsetsZero
    var adjustsImageWhenHighlighted: Bool // default is YES. if YES, image is drawn darker when highlighted(pressed)
    var adjustsImageWhenDisabled: Bool // default is YES. if YES, image is drawn lighter when disabled
    var showsTouchWhenHighlighted: Bool // default is NO. if YES, show a simple feedback (currently a glow) while highlighted
    @availability(iOS, introduced=5.0)
    var tintColor: UIColor? // The tintColor is inherited through the superview hierarchy. See UIView for more information.
    var buttonType: UIButtonType { get }

    // you can set the image, title color, title shadow color, and background image to use for each state. you can specify data
    // for a combined state by using the flags added together. in general, you should specify a value for the normal state to be used
    // by other states which don't have a custom value set

    func setTitle(title: String?, forState state: UIControlState) // default is nil. title is assumed to be single line
    func setTitleColor(color: UIColor?, forState state: UIControlState) // default if nil. use opaque white
    func setTitleShadowColor(color: UIColor?, forState state: UIControlState) // default is nil. use 50% black
    func setImage(image: UIImage?, forState state: UIControlState) // default is nil. should be same size if different for different states
    func setBackgroundImage(image: UIImage?, forState state: UIControlState) // default is nil
    @availability(iOS, introduced=6.0)
    func setAttributedTitle(title: NSAttributedString!, forState state: UIControlState) // default is nil. title is assumed to be single line

    func titleForState(state: UIControlState) -> String? // these getters only take a single state value
    func titleColorForState(state: UIControlState) -> UIColor?
    func titleShadowColorForState(state: UIControlState) -> UIColor?
    func imageForState(state: UIControlState) -> UIImage?
    func backgroundImageForState(state: UIControlState) -> UIImage?
    @availability(iOS, introduced=6.0)
    func attributedTitleForState(state: UIControlState) -> NSAttributedString?

    // these are the values that will be used for the current state. you can also use these for overrides. a heuristic will be used to
    // determine what image to choose based on the explict states set. For example, the 'normal' state value will be used for all states
    // that don't have their own image defined.

    var currentTitle: String? { get } // normal/highlighted/selected/disabled. can return nil
    var currentTitleColor: UIColor! { get } // normal/highlighted/selected/disabled. always returns non-nil. default is white(1,1)
    var currentTitleShadowColor: UIColor? { get } // normal/highlighted/selected/disabled. default is white(0,0.5).
    var currentImage: UIImage? { get } // normal/highlighted/selected/disabled. can return nil
    var currentBackgroundImage: UIImage? { get } // normal/highlighted/selected/disabled. can return nil
    @availability(iOS, introduced=6.0)
    var currentAttributedTitle: NSAttributedString? { get } // normal/highlighted/selected/disabled. can return nil

    // return title and image views. will always create them if necessary. always returns nil for system buttons
    @availability(iOS, introduced=3.0)
    var titleLabel: UILabel? { get }
    @availability(iOS, introduced=3.0)
    var imageView: UIImageView? { get }

    // these return the rectangle for the background (assumes bounds), the content (image + title) and for the image and title separately. the content rect is calculated based
    // on the title and image size and padding and then adjusted based on the control content alignment. there are no draw methods since the contents
    // are rendered in separate subviews (UIImageView, UILabel)

    func backgroundRectForBounds(bounds: CGRect) -> CGRect
    func contentRectForBounds(bounds: CGRect) -> CGRect
    func titleRectForContentRect(contentRect: CGRect) -> CGRect
    func imageRectForContentRect(contentRect: CGRect) -> CGRect
}

Related posts

Recent Viewed