jjzjj

attributedString

全部标签

ios - UITextView 文字背景色

我正在尝试获得一个透明的UITextView,并且我知道如何设置它。我还想要的就像已显示文本下方的彩色背景。同样,TextView背景会将整个View矩形设置为给定颜色,我想要的是文本下方的颜色。有什么简单的方法可以实现这样的目标吗? 最佳答案 据我所知,您正试图在文本上实现突出显示效果。如果是这种情况,您可以使用NSAttributedString。它允许您设置文本的背景颜色,而不是View背景。NSMutableAttributedString*attributedString=[[NSMutableAttributedStri

ios - 解析标记时 OHAttributedLabel 的格式问题

在属性列表中我有这样一个字符串:A|picture|isworth*1000\*words.显然“图片”应该是斜体,“1000”应该是粗体。我正在尝试使用OHAttributedLabel显示文本:NSString*theString=[pListDataobjectForKey:@"theString"];NSMutableAttributedString*attrStr=[OHASBasicMarkupParserattributedStringByProcessingMarkupInString:theString];self.myLabel.attributedText=att

ios - 如何知道 UILabel 中的单词是否被剪切

我尝试开发自动收缩功能。我已将文本设置为固定大小的UILabel。之后,我降低字体大小并检查文本是否适合给定的容器大小。问题是如果单词长于容器宽度,UILabel会忽略NSLineBreakByWordWrapping。导致我把尾词删掉了。代码如下:-(void)setCardText:(NSString*)txt{NSMutableAttributedString*attributedString=[[NSMutableAttributedStringalloc]initWithString:txt];NSMutableParagraphStyle*paragraphStyle=[[

ios - 具有多种字体颜色的 UILabel 文本

有没有办法让UILabel的textColor属性是两个不同的UIColors?基本上我试图让UILabeltextproperty中的第一个字符为greenColor其余为blackColor。我想避免使用两个不同的UILabels,因为我可能想更改绿色字符在文本中的位置。 最佳答案 从ios6开始,您可以执行以下操作:NSMutableAttributedString*attributedString=[[NSMutableAttributedStringalloc]initWithString:string];[attribu

ios - 如何删除和替换 NSAttributedString 中的 NSTextAttachment

我有一个可变的属性字符串,我在其中添加了图像文本附件。NSMutableAttributedString*attributedString=[_textField.attributedTextmutableCopy];NSMutableDictionary*dict=[_homeFeedCommentsViewController.inputData.array_extraElementsobjectAtIndex:0];NSNumber*indexObject=[NSNumbernumberWithUnsignedLong:attributedString.length];[dict

ios - 在 iOS6 上的 UITextView 上使用 attributedText (NSAttributedString) 仅适用于段落样式或字体,但不能同时适用于两者

我一直在尝试使用UITextView的attributedText属性为我的自定义UITextView添加可调整的行高。我的代码在模拟器中运行良好,但我无法使其在iPhone5上运行。如果我删除字体行,行高会起作用,但文本会恢复为默认的较小字体。如果我添加字体,字体可以工作,但段落样式会被忽略。我已经在具有相同行为的新应用程序中的普通UITextView上尝试了代码,这让我认为这是一个iOS6错误。有没有人有更好的运气?我还尝试了各种UITextView替代品来添加行高功能,但到目前为止没有任何效果。我的代码是这样的:...NSMutableParagraphStyle*paragra

iphone - 使用 NSAttributedString 为 UILabel 设置突出显示的文本颜色。?

我在表格View单元格上使用标签。已为单元格分配了一个属性字符串,但问题是在选择时单元格文本不会为属性字符串变成白色。有什么办法可以解决吗?感谢任何帮助。这是我的代码。-(UITableViewCell*)tableView:(UITableView*)tableViewcellForRowAtIndexPath:(NSIndexPath*)indexPath{staticNSString*CellIdentifier=@"Cell";LHSearchViewCell*cell=[LHSearchViewCellcellForTableView:tableViewfromNib:_ce

ios - 带有表情符号的属性字符串 - 适当的高度

我正在尝试获取属性字符串的高度。这按预期工作:[attrStringboundingRectWithSize:sizeoptions:(NSStringDrawingUsesLineFragmentOrigin|NSStringDrawingTruncatesLastVisibleLine)context:NULL]...除非字符串包含表情符号。使用表情符号时,字符串会在标签底部被截断。我需要做什么特别的事情吗? 最佳答案 我知道这是一篇旧文章,但有人可能仍然觉得它有用,您可以转到核心文本,让它为您完成艰苦的工作!staticinl

ios - 如何更改一行中单个字母或一个单词的颜色

如何在AlertView中更改“消息”中单词的颜色@@IBActionfuncbtn_instructions(sender:UIButton){letalertView=UNAlertView(title:"MyTitle",message:"Heregreentext,hereredtext")alertView.show()抱歉,如果问题不正确。 最佳答案 正如我在上面的评论中所写,UIAlertView已被弃用,因此您必须改用UIAlertController。但是,您可以为消息设置属性字符串,使用(非快速的)键值编码(因为

ios - boundingRectForGlyphRange 始终返回字体大小为 12 的矩形

我正在尝试使用boundingRectForGlyphRange方法计算单个字形的矩形。一切正常,除了它总是返回矩形,就好像字体大小是12一样。尽管我在属性字符串中将它设置为20。letfont=UIFont.systemFontOfSize(20)varattributedString=NSMutableAttributedString(string:text)letrange=NSRange(location:0,length:countElements(text))attributedString.addAttribute(NSFontAttributeName,value:fo