技術(shù)開(kāi)發(fā):胡凱凡
郵箱:975293830@qq.com? ? jsmnhkh@gmail.com? ??
手機(jī)號(hào)碼:13225225982
swift 改變UIlabel的方法
extension UILabel{
? ? /**? 改變字間距? */
? ? funcchangeWordSpace(space:CGFloat) {
? ? ? ? ifself.text==nil||self.text==""{
? ? ? ? ? ? return
? ? ? ? }
? ? ? ? lettext =self.text
? ? ? ? letattributedString =NSMutableAttributedString.init(string: text!, attributes: [NSAttributedStringKey.kern:space])
? ? ? ? letparagraphStyle =NSMutableParagraphStyle()
? ? ? ? attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: .init(location:0, length: (text?.count)!))
? ? ? ? self.attributedText= attributedString
? ? ? ? self.sizeToFit()
? ? }
? ? /**? 改變字間距和行間距? */
? ? funcchangeSpace(lineSpace:CGFloat, wordSpace:CGFloat) {
? ? ? ? ifself.text==nil||self.text==""{
? ? ? ? ? ? return
? ? ? ? }
? ? ? ? lettext =self.text
? ? ? ? letattributedString =NSMutableAttributedString.init(string: text!, attributes: [NSAttributedStringKey.kern:wordSpace])
? ? ? ? letparagraphStyle =NSMutableParagraphStyle()
? ? ? ? paragraphStyle.lineSpacing= lineSpace
? ? ? ? attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: .init(location:0, length: (text?.count)!))
? ? ? ? self.attributedText= attributedString
? ? ? ? self.sizeToFit()
? ? }
? ? /**? 改變行間距? */
? ? funcchangeLineSpace(space:CGFloat) {
? ? ? ? ifself.text==nil||self.text==""{
? ? ? ? ? ? return
? ? ? ? }
? ? ? ? lettext =self.text
? ? ? ? letattributedString =NSMutableAttributedString.init(string: text!)
? ? ? ? letparagraphStyle =NSMutableParagraphStyle()
? ? ? ? paragraphStyle.lineSpacing= space
? ? ? ? attributedString.addAttribute(NSAttributedStringKey.paragraphStyle, value: paragraphStyle, range: .init(location:0, length: (text?.count)!))
? ? ? ? self.attributedText= attributedString
? ? ? ? self.sizeToFit()
? ? }
}
swift將UIImage保存到相冊(cè)
extension UIImage {
? ? funcsaveImage() {
? ? ? ? PHPhotoLibrary.shared().performChanges({
? ? ? ? ? ? PHAssetChangeRequest.creationRequestForAsset(from: self)
? ? ? ? }) { (isSuccess, error)in
? ? ? ? ? ? print("\(isSuccess)----\(String(describing: error))")
? ? ? ? ? ? ifisSuccess {
? ? ? ? ? ? ? ? //MessateAlert.Use(titleStr: "保存成功")
? ? ? ? ? ? ? ? print("保存成功")
? ? ? ? ? ? }else{
? ? ? ? ? ? ? ? print("error---->\(String(describing: error))")
? ? ? ? ? ? ? ? //MessateAlert.Use(titleStr: "系統(tǒng)問(wèn)題谚中,保存失敗")
? ? ? ? ? ? ? ? print("系統(tǒng)問(wèn)題启妹,保存失敗")
? ? ? ? ? ? }
? ? ? ? }
? ? }
}