- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
你好我正在做一个 Twitter 应用程序,我想给主题标签、用户名和 URL 上色这是我的手机上的课
class TweetTableViewCell: UITableViewCell
{
var tweet: Tweet? {
didSet {
updateUI()
}
}
@IBOutlet weak var tweetProfileImageView: UIImageView!
@IBOutlet weak var tweetScreenNameLabel: UILabel!
@IBOutlet weak var tweetTextLabel: UILabel!
@IBOutlet weak var tweetCreatedLabel: UILabel!
func updateUI() {
tweetTextLabel?.attributedText = nil
tweetScreenNameLabel?.text = nil
tweetProfileImageView?.image = nil
tweetCreatedLabel?.text = nil
if let tweet = self.tweet
{
tweetTextLabel?.text = tweet.text
if tweetTextLabel?.text != nil {
for _ in tweet.media {
tweetTextLabel.text! += " 📷"
}
for user in tweet.userMentions{
tweetTextLabel.attributedText = NSAttributedString(string:"\(user.keyword)")
}
}
tweetScreenNameLabel?.text = "\(tweet.user)"
if let profileImageURL = tweet.user.profileImageURL {
let qos = Int(QOS_CLASS_USER_INITIATED.value)
dispatch_async(dispatch_get_global_queue(qos, 0)) { () -> Void in
if let imageData = NSData(contentsOfURL: profileImageURL) {
dispatch_async(dispatch_get_main_queue()){
if profileImageURL == tweet.user.profileImageURL{
self.tweetProfileImageView?.image = UIImage(data: imageData)
}
}}
}
}
let formatter = NSDateFormatter()
if NSDate().timeIntervalSinceDate(tweet.created) > 24*60*60 {
formatter.dateStyle = NSDateFormatterStyle.ShortStyle
} else {
formatter.timeStyle = NSDateFormatterStyle.ShortStyle
}
tweetCreatedLabel?.text = formatter.stringFromDate(tweet.created)
}
}
问题就在这里
for user in tweet.userMentions{
tweetTextLabel.attributedText = NSMutableAttributedString(string:"\(user.keyword)")
}
我不知道如何给它上色(attributedText)。我有带主题标签的字符串,用户名。我正在尝试使用用户名
更新
for user in tweet.userMentions{
//tweetTextLabel.attributedText = NSMutableAttributedString(string:"\(user.keyword)")
var attributedText = tweetTextLabel.attributedText
var userName:NSString = user.keyword
var atrString = NSMutableAttributedString(string:tweetTextLabel.text!)
atrString.addAttribute(NSForegroundColorAttributeName, value: UIColor.redColor(), range: fullString.rangeOfString(userName))
attributedText = atrString
}
并且是这样说的;它之前是有效的:使用未解析的标识符“fullString”
最佳答案
试试这个:
var attrs = [NSForegroundColorAttributeName : UIColor.redColor()]
var atrText = NSMutableAttributedString(string:"text", attributes:attrs)
tweetTextLabel.attributedText = atrText;
关于ios - 用 attributedText 给 UILabel 上色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29691643/
通过阅读文档,我确信这是明确声明的,但添加图标仍然是灰色的。 class _TaskState extends State { @override Widget b
通过阅读文档,我确信这是明确声明的,但添加图标仍然是灰色的。 class _TaskState extends State { @override Widget b
这个问题在这里已经有了答案: Get random elements from array in Swift (6 个答案) 关闭 7 年前。
你好,我有一个表,其中包含一些字段,例如 这里我想为表格整行设置颜色..意味着如果 ASR 值是 75 到 100 应该得到一种颜色,50 到 75 应该得到另一种颜色,低于 50 应该得到另一种颜色
如何为 fish 中的 ls 命令着色?我在 Mac 上使用带有适当字体等的 ITerm2。由于某种原因它停止在我的电脑上工作。当我做推荐的时候 function ls command ls
我尝试在 -webkit-transform:rotate(45deg) skew(5deg); 上添加颜色或背景色,但我没有尝试。请帮助我。 我有这个 Sencha Touch 的代码: .x-ch
我使用默认配色方案(稍作改动),没有着色插件。 不幸的是,现在我需要在无法使用 256 色模式的远程机器上工作(使用 Putty)。这看起来很纯净。 我尝试修复它,但我无法理解不同部分的突出显示名称是
是否可以给 scipy.spatial.Voronoi 上色?图表? I know it is. 但现在我的目标是根据色标为每个单元格着色以表示物理量。 如下图(PRL 107, 155704 (20
我正在使用 ggplot2 geom_bar 制作标准条形图。我试图用与最低值的条不同的颜色填充最高值的条。 例如, ggplot(mtcars, aes(x=as.factor(cyl) )) +
我正在尝试对 map 上的特定图 block 进行样式设置,但不知道如何设置。谷歌有一个我在这里指的图 block 的示例: https://developers.google.com/maps/do
我想通过添加一个名为“色调”的 Canvas 来为 Canvas 上的 png 着色,该 Canvas 会将颜色分配给主 Canvas 上的 png。但根本没有绘制任何东西: js fiddel co
我创建了一个模糊 View 并添加到主视图的 subview 中。这是我的代码: let blurEffect = UIBlurEffect(style: UIBlurEffectStyle.ligh
我正在尝试实现与 this function in Matlab 相同的行为,其中每个箭头的颜色对应于它的大小和方向,本质上是从轮子中绘制它的颜色。我看到了this question ,但它似乎只适用
假设有一个fa图标: //这段代码不正确 我的目的是为奖杯本身着色,而不是为奖杯外的背景着色。现在我的奖杯看起来是黑色的,我怎样才能把奖杯的颜色改成黄色? 最佳答案 Font awesome 是
你好我正在做一个 Twitter 应用程序,我想给主题标签、用户名和 URL 上色这是我的手机上的课 class TweetTableViewCell: UITableViewCell { var t
我在下面尝试过,但它在解析颜色时抛出了一个语句错误。提前致谢。 hexColorStr = "0x0976b8" view.setBackgroundColor(Color.parseColor(St
我需要显示一个由圆形和多边形组成的 map ,每个圆形或多边形可能有不同的颜色。 我最初的计划是子类化 MKCircle 和 MKPolygon 并为我的 Region 类添加一个实例变量(其中包含将
我有以下用于生成箭头线的 ng 模板:
我正在使用 Git,使用 Windows 7、PowerShell 和 Posh-Git。我有以下别名设置: ls = log --pretty=tformat:"%C(yellow)%h\\ %C(
我是一名优秀的程序员,十分优秀!