2017-09-22 4 views
2

레이블 내에 텍스트 주위에 윤곽선을 그리는 UIOutlineLabel의 사용자 지정 클래스가 있습니다. Swift 4로 업데이트 한 후 다음과 같은 오류가 나타납니다.
'[String : Any]'값을 예상 인수 유형 '[NSAttributedStringKey : Any]?'으로 변환 할 수 없습니다.XCode 9 : '[String : Any]'유형의 값을 예상 인수 유형 '[NSAttributedStringKey : Any]'로 변환 할 수 없습니다.

나는에 strokeTextAttributes 변경 시도 :

as! [NSAttributedStringKey : Any] 

그러나 이것은 런타임 오류가 발생합니다.

이도의 스위프트 언어 런타임 경고입니다 '사용되지 UIOutlineLabel setOutlineWidth 및 스위프트 사에서 제거 될 예정입니다'& 'UIOutlineLabel setOutlineColor는 사용되지 않으며 스위프트 사에서 제거됩니다'.

기존 코드 :

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

답변

2

난 당신이 사용한다고 생각 : 속성 인수가이의 런타임 경고에 대한 충돌하지만 해결 [NSAttributedStringKey : Any]? 유형

+0

감사를 기대

override func drawText(in rect: CGRect) { let strokeTextAtrributes: [NSAttributedStringKey : Any] = [ NSAttributedStringKey.strokeColor : outlineColor, NSAttributedStringKey.strokeWidth : -1 * outlineWidth, ] self.attributedText = NSAttributedString(string: self.text ?? "", attributes: strokeTextAttributes) super.drawText(in: rect) } 

때문에 ' UIOutlineLabel setOutlineWidth는 사용되지 않으며 Swift 4 '에서 제거됩니다.'UIOutlineLabel setOutlineColor는 더 이상 사용되지 않으며 Swift 4 '에서 제거됩니다. –

+0

디버그 콘솔에 대안으로 나타나지 않습니까? –

관련 문제