我試圖使用Unicode專用空格字符並將其設置爲UILabel
的text
屬性。這是使用RubyMotion。通過RubyMotion在UILabel中使用unicode字符
我想要的字符是Entypo系列的一部分,並且是U+1F554
(🕔
)。
我創建了一個新的UILabel
:
@lblIcon = UILabel.alloc.initWithFrame([[0,(self.view.frame.size.height/2) - 128],[self.view.frame.size.width,96]])
,並設置它的文本使用pack
語法的Unicode字符。
@lblIcon.text = [0x1f554].pack('U*')
我然後應用圖標,字體,並將其添加到視圖:
ico_font = UIFont.fontWithName("Entypo", size:48)
@lblIcon.font = ico_font
self.view.addSubview @lblIcon
當我運行rake
並試圖啓動應用程序,我得到以下崩潰的消息:
*** Terminating app due to uncaught exception 'RuntimeError', reason: 'ui_label.rb:16:in `font=:': NSInvalidArgumentException: NSConcreteMutableAttributedString addAttribute:value:range:: nil value (RuntimeError)
我也試過
@lblIcon.text = [0x1f554].pack('U*') + ""
和
@lblIcon.text = "\U1F554"
無濟於事。
什麼是正確的方法來創建一個字符串組成的Unicode字符適用於UILabel
?
我認爲提交支持請求是您最好的選擇。這聽起來像一個RubyMotion的錯誤。 –