I draw the text using Swift String.drawWithRect method. It works fine when drawing in drawRect(). But when I place the code inside dispatch_after method it isn't drawn.
Here is the code:
let dispatchTime = dispatch_time(DISPATCH_TIME_NOW, Int64(Double(2)*Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue()){
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = .Center
let attrs = [NSFontAttributeName: UIFont.systemFontOfSize(12),
NSForegroundColorAttributeName: UIColor.grayColor(),
NSParagraphStyleAttributeName: paragraphStyle]
let string = "Test"
let x = 100.0
let y = 100.0
string.drawWithRect(CGRect(x: x, y: y, width: 100.0, height: 100.0), options: .UsesLineFragmentOrigin, attributes: attrs, context: nil)
}
I guess it's related to drawing context but can't figure out what to do. How to switch context, in order to draw text using dispatch_after? Thanks in advance.