UILabel实现左右对齐 以及 String去掉空格

UILabel实现左右对齐 
static func getJustFieldLabelAttributetext(_ text:String)->NSMutableAttributedString {
        let paragraphStyle = NSMutableParagraphStyle.init()
        paragraphStyle.alignment = .justified
        let attriButting:NSMutableAttributedString = NSMutableAttributedString.init(string: text)
        attriButting.addAttribute(NSAttributedStringKey.font, value:UIFont.systemFont(ofSize: 17), range:NSMakeRange(0,text.count))
        paragraphStyle.lineSpacing = 5
        attriButting.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: NSMakeRange(0,text.count))
        attriButting.addAttribute(NSAttributedStringKey.underlineStyle, value:NSNumber.init(value:Int8(NSUnderlineStyle.styleNone.rawValue)), range: NSMakeRange(0,text.count))
       return attriButting
    }
*String 去除头尾空格
static func getCraftMaterials(_ crafting: String) -> String{
         let whitespace =  NSCharacterSet.whitespacesAndNewlines
         return crafting.trimmingCharacters(in: whitespace)
    }
 *去掉首尾空格 包括后面的换行 \n
    var removeHeadAndTailSpacePro:String {
        let whitespace = NSCharacterSet.whitespacesAndNewlines
        return self.trimmingCharacters(in: whitespace)
    }
 *去掉所有空格
    var removeAllSapce: String {
        return self.replacingOccurrences(of: " ", with: "", options: .literal, range: nil)
    }
 *去掉首尾空格 后 指定开头空格数
    func beginSpaceNum(num: Int) -> String {
        var beginSpace = ""
        for _ in 0..

你可能感兴趣的:(UILabel实现左右对齐 以及 String去掉空格)