Created
November 22, 2016 09:42
-
-
Save sergii-frost/0d74cd727fa67f2fdf1267bc65de546e to your computer and use it in GitHub Desktop.
NSMutableAttributedString (Swift) Playground
This file contains 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
//: Playground - noun: a place where people can play | |
import UIKit | |
let creator = "Awesome Me" | |
let teamName = "Awesome Team" | |
let groupName = "Awesome Group" | |
func getHeader(creator: String, team: String, group: String? = nil) -> NSAttributedString { | |
let result: NSMutableAttributedString = NSMutableAttributedString() | |
if let group = group { | |
result.appendAttributedString(NSAttributedString(string: "\(creator) > ", attributes: [NSForegroundColorAttributeName: UIColor.blackColor()])) | |
result.appendAttributedString(NSAttributedString(string: " \(team) ", attributes: [NSForegroundColorAttributeName: UIColor.orangeColor()])) | |
result.appendAttributedString(NSAttributedString(string: " & ", attributes: [NSForegroundColorAttributeName: UIColor.blackColor()])) | |
result.appendAttributedString(NSAttributedString(string: "\(group)", attributes: [NSForegroundColorAttributeName: UIColor.orangeColor()])) | |
} else { | |
result.appendAttributedString(NSAttributedString(string: "\(creator) > ", attributes: [NSForegroundColorAttributeName: UIColor.blackColor()])) | |
result.appendAttributedString(NSAttributedString(string: " \(team) ", attributes: [NSForegroundColorAttributeName: UIColor.orangeColor()])) | |
} | |
return result | |
} | |
getHeader(creator, team: teamName, group: groupName) | |
getHeader(creator, team: teamName) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment