Visual_Novel_iOS/crush/Crush/Src/Components/UI/Buttons/StyleButtonExt.swift

61 lines
2.3 KiB
Swift
Raw Normal View History

2025-10-09 10:29:35 +00:00
//
// StyleButtonExt.swift
// Crush
//
// Created by Leon on 2025/8/26.
//
extension StyleButton{
/// Coin : price * 100
static func getUnlockAttributeTitleByCoin(coin: Int, string: String = "") -> NSAttributedString {
let coin = Coin(cents: coin)
let text = " \(coin.thousandthsFormatted) \(string)"
let attributedString = NSMutableAttributedString()
if let iconImage = UIImage(named: "icon_32_diamond") { //
let attachment = NSTextAttachment()
attachment.image = iconImage
let iconSize = CGSize(width: 24, height: 24) //
attachment.bounds = CGRect(origin: .init(x: 0, y: -4), size: iconSize)
let iconAttributedString = NSAttributedString(attachment: attachment)
attributedString.append(iconAttributedString)
}
//
let textAttributedString = text.withAttributes([
.font(.t.tll), //
.textColor(.white),
])
attributedString.append(textAttributedString)
return attributedString
}
/// vip + AttributeString
static func getVIPBlackTitleByWords(words: String) -> NSAttributedString {
// let text = " \(words)"
// let attributedString = NSMutableAttributedString()
// if let iconImage = MWIconFont.image(fromIcon: .iconVip, size: CGSize(width: 24, height: 24), color: .black) { //
// let attachment = NSTextAttachment()
// attachment.image = iconImage
//
// let iconSize = CGSize(width: 24, height: 24) //
// attachment.bounds = CGRect(origin: .init(x: 0, y: -4), size: iconSize)
//
// let iconAttributedString = NSAttributedString(attachment: attachment)
// attributedString.append(iconAttributedString)
// }
//
// //
// let textAttributedString = text.withAttributes([
// .font(.t.tbsl), //
// .textColor(.black),
// ])
// attributedString.append(textAttributedString)
// return attributedString
return NSAttributedString.getIconTitleAttributeByWords(words: words, icon:.iconVip, textFont: .t.tll)
}
}