作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我一直在为这个问题苦苦挣扎。但是我正在处理远程通知,老实说,我似乎无法找到一种方法来将通知的第一行加粗。这是我的代码
let boldUser = backendless!.userService.currentUser.name!
let string: NSString = "\(boldUser) \nMessage: \(message)" as NSString
let attributedString = NSMutableAttributedString(string: string as String, attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 15.0)])
let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 15.0)]
// Part of string to be bold
attributedString.addAttributes(boldFontAttribute, range: string.range(of: "\(boldUser)" as String))
publishOptions.assignHeaders(["ios-alert" : "\(string)", "ios-badge" : "\(counter)", "ios-sound" : "message_tone_3.mp3"])
我不明白为什么这不起作用。据我所知,我做的一切都是正确的,但是当我测试时,没有一个通知是粗体的。我正在尝试将第一行加粗。
最佳答案
像这样使用 NSRange:
let string: NSString = "\(boldUser) \nMessage: \(message)" as NSString
let attributedString = NSMutableAttributedString(string: string as String, attributes: [NSFontAttributeName:UIFont.systemFont(ofSize: 15.0)])
let boldFontAttribute = [NSFontAttributeName: UIFont.boldSystemFont(ofSize: 15.0)]
// Part of string to be bold
// attributedString.addAttributes(boldFontAttribute, range: NSRange(location:0, length:StringArray[0].characters.count))
// Part of string to be bold
attributedString.addAttributes(boldFontAttribute, range: NSRange(location:0, length:StringArray[0].characters.count))
关于ios - 在 Swift 3 中加粗字符串的单个部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44062804/
下面是我用来制作 1px 文本描边轮廓的代码。但是如何使轮廓变粗呢?如果我只是用“5px”替换所有“1px”,结果看起来很疯狂。 HTML Hello! CSS .element { color:
我是一名优秀的程序员,十分优秀!