我得到两个错误,因为我尝试我的应用程序升级到斯威夫特2如何让kCGPathStroke在Swift 2中工作?
两个错误是:
Use of unresolved identifier 'kCGPathStroke'
和:
Cannot convert value of type 'NSMutableDictionary' to expected argument type '[String : AnyObject]?'
两个问题在评论代码如下。我查看了文档,看起来像kCGPathStroke
仍然存在,所以我很困惑,为什么这是打破。我究竟做错了什么?
import UIKit
import CoreGraphics
class MIBadgeLabel: UILabel {
override func drawRect(rect: CGRect)
{
// Drawing code
let ctx: CGContextRef = UIGraphicsGetCurrentContext()!
let borderPath: UIBezierPath = UIBezierPath(roundedRect: rect, byRoundingCorners:UIRectCorner.AllCorners, cornerRadii: CGSizeMake(10.0, 10.0))
CGContextSetFillColorWithColor(ctx, UIColor.whiteColor().CGColor)
CGContextSaveGState(ctx)
CGContextAddPath(ctx, borderPath.CGPath)
CGContextSetLineWidth(ctx, 4.0)
CGContextSetStrokeColorWithColor(ctx, UIColor.clearColor().CGColor)
CGContextDrawPath(ctx, kCGPathStroke) //Swift 2 error
CGContextRestoreGState(ctx)
CGContextSaveGState(ctx)
// CGContextSetFillColorWithColor(ctx, UIColor.whiteColor().CGColor)
var textFrame: CGRect = rect
let labelString: NSString = self.text! as NSString
let textSize: CGSize = labelString.sizeWithAttributes([NSFontAttributeName : UIFont.systemFontOfSize(13.0)])
textFrame.size.height = textSize.height
textFrame.origin.y = rect.origin.y + ceil((rect.size.height - textFrame.size.height)/2.0)
let paragraphStyle: NSMutableParagraphStyle = NSMutableParagraphStyle();
paragraphStyle.alignment = .Center
var attributes: NSMutableDictionary = [NSFontAttributeName: UIFont.systemFontOfSize(13.0), NSForegroundColorAttributeName : UIColor.whiteColor(), NSParagraphStyleAttributeName:paragraphStyle]
labelString.drawInRect(textFrame, withAttributes: attributes) // Swift 2 error
}
}
为什么下来投票? –