@buoge
2017-06-29T08:07:31.000000Z
字数 804
阅读 1179
iOS

商品合计,活动优惠,实付,都是对齐的,后面的冒号":",是单独一个lable,实现,不然计算两端对齐一直不对
// 调用方式justified(mLableNote)// 核心方法func justified(_ mLable:UILabel) {let text = mLable.textlet textSize = text?.characters.count ?? 2if (text == nil) {return}let font = FontUtils.getThinFont(13)let textAttributes = [NSFontAttributeName: font]let textString = text! as NSStringlet attributeLength = textSize - 1let textRectSize = textString.boundingRect(with: CGSize(width: self.frame.size.width,height:2000), options: .usesLineFragmentOrigin, attributes: textAttributes, context: nil).sizelet margin = (mLable.frame.size.width - textRectSize.width) / CGFloat(attributeLength)let attributedString = NSMutableAttributedString(string: text ?? "")attributedString.addAttribute(NSKernAttributeName, value: margin, range: NSRange(location: 0,length: attributeLength) )mLable.attributedText = attributedString}
