我正在构建一个业余项目来尝试 iOS 开发,并决定将其作为一个消息传递应用程序。我在消息正文下方的消息中添加了时间戳,但仍在气泡内,因为我喜欢这样看起来比在气泡外更好。 iOS 会自动格式化这些数字以包含在日历中。有没有办法为这些数字转义这种格式?我想在用户输入时间和日期时保留它,因为这非常有用。
下面是添加消息正文的 block ,以及我所指内容的屏幕截图。
override func didPressSendButton(button: UIButton!, withMessageText text: String!, senderId: String!, senderDisplayName: String!, date: NSDate!) {
JSQSystemSoundPlayer.jsq_playMessageSentSound()
let date = NSDate()
let calendar = NSCalendar.currentCalendar()
let components = calendar.components(.CalendarUnitHour | .CalendarUnitMinute, fromDate: date)
let hour = components.hour
var minutes = components.minute
if minutes < 10 {
var minutes = String(minutes)
minutes = String(format: "%02d", minutes)
}
var newText = text + "\n\n \(hour):\(minutes)"
var newMessage = JSQMessage(senderId: senderId, displayName: senderDisplayName, text: newText);
messages += [newMessage]
self.finishSendingMessage()
}
最佳答案
在创建单元格的 JSQMessagesViewController 中,数据检测器类型设置为全部。
Line 539 of JSQMessagesViewController.m
cell.textView.dataDetectorTypes = UIDataDetectorTypeAll;
cell.backgroundColor = [UIColor clearColor];
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
cell.layer.shouldRasterize = YES;
return cell;
您可以将其设置为 UIDataDetectorTypeNone .
关于ios - 如何防止 iOS 在 Swift 中自动为数字加下划线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32318666/