在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
func FuWenBen() -> NSMutableAttributedString { //定义富文本即有格式的字符串 let attributedStrM : NSMutableAttributedString = NSMutableAttributedString() // 左上角星星 let xingxing = NSAttributedString.init(string: "*", attributes: [NSAttributedString.Key.backgroundColor : UIColor.black , NSAttributedString.Key.foregroundColor : UIColor.red , NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 20) ,NSAttributedString.Key.baselineOffset : (20)]) let wo = NSAttributedString.init(string: "我", attributes: [NSAttributedString.Key.backgroundColor : UIColor.gray , NSAttributedString.Key.foregroundColor : UIColor.green , NSAttributedString.Key.font : UIFont.boldSystemFont(ofSize: 30)]) let shi : NSAttributedString = NSAttributedString(string: "是", attributes: [NSAttributedString.Key.foregroundColor : UIColor.purple, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 12)]) //帅逼 let shuaibi : NSAttributedString = NSAttributedString(string: "帅逼", attributes: [NSAttributedString.Key.foregroundColor : UIColor.lightGray, NSAttributedString.Key.font : UIFont.systemFont(ofSize: 38)]) //图片 let smileImage = UIImage.init(named: "tupian") let textAttachment : NSTextAttachment = NSTextAttachment() textAttachment.image = smileImage textAttachment.bounds = CGRect(x: 0, y: -4, width: 22, height: 22) attributedStrM.append(xingxing) attributedStrM.append(wo) attributedStrM.append(shi) attributedStrM.append(shuaibi) attributedStrM.append(NSAttributedString(attachment: textAttachment)) return attributedStrM }
效果如下: |
请发表评论