func attributedText() -> NSAttributedString {
let string = termsTextView.text as NSString
let attributedString = NSMutableAttributedString(
string: string as String,
attributes: [NSAttributedString.Key.font: UIFont.systemFont(ofSize: 15.0)]
)
let boldFontAttribute = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 15.0)]
let semiBoldFontAttribute = [NSAttributedString.Key.font: UIFont.boldSystemFont(ofSize: 12.0)]
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "You"))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "Services."))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "1. OVERVIEW."))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "II. TERMS AND CONDITIONS"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "A. Adults & Children."))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "18 Years Old and Older"))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "Under 18 Years Old"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "B. Availability"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "C. Authorized Use"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "D. Linking (To & From) the Website; Advertisers"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "E. Privacy Policy"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "F. Prohibition against Harmful Transmissions & Appropriate Use of Website"))
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "User Content"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "G. Disclaimer of Warranties; Limitation Of Liability"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "I. Indemnification"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "J. Severability"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "K. Entire Agreement & Priority"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "L. Choice Of Law"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "M. Venue; Personal Jurisdiction; Service of Process"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "N. Headings For Convenience Only"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "O. Waiver"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "Q. Copyright Complaints"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "R. Contact"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "S. Local Laws"))
attributedString.addAttributes(semiBoldFontAttribute, range: string.range(of: "T. Prohibited Conduct"))
return attributedString
}
This is my code to set attributedText
on UITextView
I am trying to refactor using different loops to remove repeated code as much as possible. like using enum
or switch Case
Any idea how can i achieve this? Thanks in