Skip to content

ANSCoder/CustomLabel

Repository files navigation

CustomLabel

Blog for Custom UILabel Effects.

Check full blog from here.

Make Custom label for OutLine effect

let strokeTextAttributes = [ 
    NSAttributedStringKey.strokeColor : UIColor.red,
    NSAttributedStringKey.foregroundColor : UIColor.white,
    NSAttributedStringKey.strokeWidth : -4.0,
    NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 30)]
    as [NSAttributedStringKey : Any]
//Making outline here
labelOutLine.attributedText = NSMutableAttributedString(string: “Your outline text”, attributes: strokeTextAttributes) 

Make Custom label for UnderLine effect

let attributedString = NSMutableAttributedString(string: “Your UnderLine text”)
attributedString.addAttribute(NSAttributedStringKey.underlineStyle, value: NSUnderlineStyle.styleSingle.rawValue, range: NSRange(location: 0, length: attributedString.length))
//Underline effect here
labelUnderLine.attributedText = attributedString