私はUIOutlineLabelというカスタムクラスを持っています。これは、ラベル内のテキストの周りにアウトラインを描画します。 Swift 4にアップデートしたので、次のエラーが発生します。
'[String:Any]'の値を期待される引数の型[NSAttributedStringKey:Any]に変換できません。XCode 9: '[String:Any]'型の値を期待される引数型 '[NSAttributedStringKey:Any]に変換できませんか?'
私はstrokeTextAttributesを変更しようとしている:
as! [NSAttributedStringKey : Any]
が、これは、実行時エラーになります。
「UIOutlineLabel setOutlineWidthが廃止されており、スウィフト4で削除されます」のスウィフト言語ランタイムの警告もあります&「のUIOutlineLabel setOutlineColorが廃止されており、スウィフト4で削除されます」。
旧コード:
import UIKit
class UIOutlineLabel: UILabel {
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
override func drawRect(rect: CGRect) {
// Drawing code
}
*/
var outlineWidth: CGFloat = 1
var outlineColor: UIColor = UIColor.white
override func drawText(in rect: CGRect) {
let strokeTextAttributes = [
NSAttributedStringKey.strokeColor.rawValue : outlineColor,
NSAttributedStringKey.strokeWidth : -1 * outlineWidth,
] as! [String : Any]
self.attributedText = NSAttributedString(string: self.text ?? "", attributes: strokeTextAttributes)
super.drawText(in: rect)
}
}
感謝を期待
ので " UIOutLabel setOutlineWidthは廃止され、Swift 4 'で削除されます。'& 'UIOutlineLabel setOutlineColorは廃止され、Swift 4'では削除されます。 –
デバッグコンソールには表示されません。 –