Last active
December 16, 2018 12:57
-
-
Save hsylife/86cb8e066da6466d415f6a70ad56ed26 to your computer and use it in GitHub Desktop.
文字につける影の比較 ref: https://qiita.com/hsylife/items/8c04bfcec6a640b38db7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@IBDesignable class ShadowAttributeSettableLabel : UILabel { | |
@IBInspectable var shadowColorForCustom: UIColor = .clear | |
@IBInspectable var shadowOffsetForCustom: CGSize = .zero | |
@IBInspectable var shadowRadiusForCustom: CGFloat = 0.0 | |
override func layoutSubviews() { | |
super.layoutSubviews() | |
guard let text = text, let attributed = attributedText else { return } | |
let mutable = NSMutableAttributedString(attributedString: attributed) | |
let shadow = createShadow() | |
let range = NSRange(location: 0, length: text.count) | |
mutable.addAttribute(.shadow, value: shadow, range: range) | |
attributedText = mutable | |
} | |
private func createShadow() -> NSShadow { | |
let shadow = NSShadow() | |
shadow.shadowColor = shadowColorForCustom | |
shadow.shadowOffset = shadowOffsetForCustom | |
shadow.shadowBlurRadius = shadowRadiusForCustom | |
return shadow | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
@IBDesignable class ShadowUIColorSettableLabel : UILabel { | |
@IBInspectable var shadowUIColor: UIColor = .clear { | |
didSet { | |
layer.shadowColor = shadowUIColor.cgColor | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment