import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
let configuration = UIImage.SymbolConfiguration(pointSize: 28, // 大小(和字体一样)
weight: .ultraLight, // 线条粗细
scale: .large) // 大小模式
let image = UIImage.init(systemName: "figure.walk.circle",
withConfiguration: configuration)
let imageView:UIImageView = UIImageView(image: image)
imageView.center = CGPoint(x: 150, y: 50)
imageView.backgroundColor = .gray
imageView.tintColor = .orange // 渲染色
self.view.addSubview(imageView)
// 和文字同时使用
let label = UILabel(frame: CGRect(x: 0, y: 200, width: UIScreen.main.bounds.width, height: 200))
label.backgroundColor = .gray
let imageAttachment = NSTextAttachment(image: image!)
let imageString = NSMutableAttributedString(attachment: imageAttachment)
let str = NSAttributedString(string: "这是拼接的内容")
imageString.append(str)
label.attributedText = imageString
view.addSubview(label)
}
}
网友评论