Search code examples
iosswifttextfontsuicolor

How to add Font with inner color and outer color


I am working on photo editing App which is in ios swift 4 and i want to give functionality as followed

enter image description here

as in image I want to give inner color and outer color for Text.but i didn't have any idea about it. how can i acheive it is there any library of function

I have tried Some property of font as i had used shadow color and background color but it does not meet my requirement. please help!


Solution

  • You can achieve this kind of functionality with an NSAttributedString:

    NSAttributedString(string: "Testing", attributes: [
    .foregroundColor: #colorLiteral(red: 0.980392158, green: 0.5607843399, blue: 0, alpha: 1),
    .strokeColor: #colorLiteral(red: 0.03990633413, green: 0.1469032466, blue: 0.7415332794, alpha: 1),
    .strokeWidth: -3,
    .font: UIFont.systemFont(ofSize: 30)])
    

    This results in a string that looks like this:

    enter image description here