SF Symbol - UIKit

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)
    }
}

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

推荐阅读更多精彩内容