技术开发:胡凯凡
邮箱: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("系统问题,保存失败")
}
}
}
}
网友评论