Facebean开发技术支持

技术开发:胡凯凡

邮箱:975293830@qq.com    jsmnhkh@gmail.com    

手机号码: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保存到相册

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: "系统问题,保存失败")

                print("系统问题,保存失败")

            }

        }

    }

}


技术开发:胡凯凡

邮箱:975293830@qq.com    jsmnhkh@gmail.com    

手机号码:13225225982

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容