ios - 如何防止 iOS 在 Swift 中自动为数字加下划线?

标签 ios swift

我正在构建一个业余项目来尝试 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()
}

enter image description here

最佳答案

在创建单元格的 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/

相关文章:

ios - 如何查看iOS11录屏是开还是关?

swift - 使用 NSDate() 作为 Parse.com 的键保存字典失败

ios - 仅当加载所有数据时才加载 CollectionView 单元格

ios - 数组中的数组(二维数组?)

ios - 如何获取本地化 "Purchased"和 "Purchased on My iPhone"播放列表的 MPMediaPlaylist?

ios - 无法将类型的值转换为预期的参数类型 NSURLSessionDelegate

swift - 我如何判断 FileHandle 什么时候没有可读的内容?

ios - iOS 给 UIView 填充多种颜色

iphone - IB 自定义 UITableViewCell - 单元格和详细文本的动态高度

Swift:覆盖采用 NSInvocation 的初始化程序