小编Ste*_*per的帖子

使用drawInRect:withAttributes对齐文本:

在我的应用程序的iOS 5版本中,我有:

[self.text drawInRect: stringRect
             withFont: [UIFont fontWithName: @"Courier" size: kCellFontSize]
        lineBreakMode: NSLineBreakByTruncatingTail
            alignment: NSTextAlignmentRight];
Run Code Online (Sandbox Code Playgroud)

我正在升级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];
Run Code Online (Sandbox Code Playgroud)

我将哪些键值对添加到字典中以获取NSLineBreakByTruncatingTailNSTextAlignmentRight

nsstring ios ios7

46
推荐指数
2
解决办法
3万
查看次数

标签 统计

ios ×1

ios7 ×1

nsstring ×1