在iOS 5的版本,我的應用程序我有:對齊文本
[self.text drawInRect: stringRect
withFont: [UIFont fontWithName: @"Courier" size: kCellFontSize]
lineBreakMode: NSLineBreakByTruncatingTail
alignment: NSTextAlignmentRight];
我升級爲iOS 7,上述方法已被棄用。我現在使用drawInRect:withAttributes:。 屬性參數是一個NSDictionary對象。我可以得到drawInRect:withAttributes:來使用這個前字體參數工作:
UIFont *font = [UIFont fontWithName: @"Courier" size: kCellFontSize];
NSDictionary *dictionary = [[NSDictionary alloc] initWithObjectsAndKeys: font, NSFontAttributeName,
nil];
[self.text drawInRect: stringRect
withAttributes: dictionary];
我添加到字典什麼鍵值對獲得NSLineBreakByTruncatingTail和NSTextAlignmentRight?
你是怎麼找到的? +1 – ViruMax
雖然我無法想象一個更短的變化 - 這當然有效,但似乎是分配工作只是爲了增加一些理由! –
如何讓字符串多行? –