Is it possible to get a listing of attributes and ranges for an NSMutableAttributedString?

前端 未结 7 1396
小蘑菇
小蘑菇 2021-02-01 12:36

I\'ve created a method that takes a NSAttributedString and I\'m looking to dynamically create a subview and label to put the string into. Because attributes like font and size n

7条回答
  •  自闭症患者
    2021-02-01 13:13

    I have modified one of the answers with suggested fixes to prevent infinite recursion and application crashes.

    @IBDesignable
    extension UITextField{
    
        @IBInspectable var placeHolderColor: UIColor? {
            get {
                if let color = self.attributedPlaceholder?.attribute(.foregroundColor, at: 0, effectiveRange: nil) as? UIColor {
                    return color
                }
                return nil
            }
            set {
                self.attributedPlaceholder = NSAttributedString(string:self.placeholder != nil ? self.placeholder! : "", attributes:[.foregroundColor: newValue!])
            }
        }
    }
    

提交回复
热议问题