美文网首页
SF Symbol - UIKit

SF Symbol - UIKit

作者: 北_极_狐 | 来源:发表于2022-07-02 11:09 被阅读0次
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)
    }
}

相关文章

网友评论

      本文标题:SF Symbol - UIKit

      本文链接:https://www.haomeiwen.com/subject/emtkbrtx.html