У меня есть UIButton
, и я пытаюсь установить заголовок, чтобы иметь 2 строки, а вторая строка должна быть меньшим шрифтом, чем первая. Вот мой код:Применение сбоев NSMutalbeAtrributedString
self.startBtn.setTitle("First\nSecond Line", forState: .Normal)
let string = NSMutableAttributedString()
string.addAttribute(NSFontAttributeName, value: UIFont.systemFontOfSize(13), range: NSMakeRange(4, 5))
self.startBtn.titleLabel?.attributedText = string
Когда я запустить приложение, я получаю следующее сообщение об ошибке:
Terminating app due to uncaught exception 'NSRangeException', reason: 'NSMutableRLEArray objectAtIndex:effectiveRange:: Out of bounds'
*** First throw call stack:
(
0 CoreFoundation 0x0000000106fbbc65 __exceptionPreprocess + 165
1 libobjc.A.dylib 0x0000000106c54bb7 objc_exception_throw + 45
2 CoreFoundation 0x0000000106fbbb9d +[NSException raise:format:] + 205
3 Foundation 0x00000001067e26ae -[NSRLEArray objectAtIndex:effectiveRange:] + 142
4 Foundation 0x00000001067fa029 -[NSConcreteMutableAttributedString addAttribute:value:range:] + 209
5 myApp 0x00000001064e0a93 _TFC7myApp18MainViewController9startTimefS0_FCSo8UIButtonT_ + 1363
6 myApp 0x00000001064e0eaa _TToFC7myApp18MainViewController9startTimefS0_FCSo8UIButtonT_ + 58
7 UIKit 0x0000000107561da2 -[UIApplication sendAction:to:from:forEvent:] + 75
8 UIKit 0x000000010767354a -[UIControl _sendActionsForEvents:withEvent:] + 467
9 UIKit 0x0000000107672919 -[UIControl touchesEnded:withEvent:] + 522
10 UIKit 0x00000001075ae998 -[UIWindow _sendTouchesForEvent:] + 735
11 UIKit 0x00000001075af2c2 -[UIWindow sendEvent:] + 682
12 UIKit 0x0000000107575581 -[UIApplication sendEvent:] + 246
13 UIKit 0x0000000107582d1c _UIApplicationHandleEventFromQueueEvent + 18265
14 UIKit 0x000000010755d5dc _UIApplicationHandleEventQueue + 2066
15 CoreFoundation 0x0000000106eef431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
16 CoreFoundation 0x0000000106ee52fd __CFRunLoopDoSources0 + 269
17 CoreFoundation 0x0000000106ee4934 __CFRunLoopRun + 868
18 CoreFoundation 0x0000000106ee4366 CFRunLoopRunSpecific + 470
19 GraphicsServices 0x00000001096cca3e GSEventRunModal + 161
20 UIKit 0x0000000107560900 UIApplicationMain + 1282
21 myApp 0x00000001064da2c7 main + 135
22 libdyld.dylib 0x0000000109ab3145 start + 1
23 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException