jjzjj

NSMutableAttributedString

全部标签

objective-c - 显示 NSMutableAttributedString

我的应用程序中有以下代码NSMutableAttributedString*string=[[NSMutableAttributedStringalloc]initWithString:self.myDisplayTxt];[stringaddAttribute:(NSString*)kCTForegroundColorAttributeNamevalue:(id)[[UIColorredColor]CGColor]range:NSMakeRange(0,5)];self.myTextView.text=string;将NSMutableAttributedString分配给UITex

ios - 粗体部分标题,iOS 7

我已经阅读了几种关于将字符串的一部分加粗的方法。但我仍然无法让它工作。这是我的代码#defineFONT_OPEN_BOLD(s)[UIFontfontWithName:@"OpenSans-Bold"size:s]在viewDidLoad函数中NSString*stringName=@"ShowTimes";UIFont*font=FONT_OPEN_BOLD(15.0f);NSMutableAttributedString*attrString=[[NSMutableAttributedStringalloc]initWithString:stringName];[attrStri

html - 如何在 iOS 中为 html 格式的字符串应用粗体?

我想使用在我的应用程序撰写邮件中打印的字符串以粗体打印文本messageBody=[NSStringstringWithFormat:@"BackgroundInformation"]; 最佳答案 WhatyoucoulddoisuseanNSAttributedString.NSString*boldFontName=[[UIFontboldSystemFontOfSize:12]fontName];NSString*yourString=...;NSRangeboldedRange=NSMakeRange(22,4);NSMut

ios - 将 HTML 翻译成 NSAttributedString 时,我可以设置默认字体吗?

我正在尝试在UILabel中显示HTML,例如NSString*htmlString=@"Somehtmlstring\nThisissometext!";NSAttributedString*attrStr=[[NSAttributedStringalloc]initWithData:[htmlStringdataUsingEncoding:NSUnicodeStringEncoding]options:@{NSDocumentTypeDocumentAttribute:NSHTMLTextDocumentType}documentAttributes:nilerror:nil];现

ios - 两个不同字体大小的自动布局 UILabels : Text Top alignment

有没有办法设置两个UILabel文本顶部对齐?两者都是不同的字体大小。 最佳答案 我可以给你看这张图片的例子:代码:-(NSMutableAttributedString*)styleSalePriceLabel:(NSString*)salePricewithFont:(UIFont*)font{if([salePricerangeOfString:@"."].location==NSNotFound){return[[NSMutableAttributedStringalloc]initWithString:salePrice]

ios - 在 cellForItemAtIndexPath 中创建带有 NSTextAttachment 的 NSMutableAttributedString 是一个坏主意(性能或设计方面)吗?

我正在我的CollectionView的cellForItemAtIndexPath方法中创建NSMutableAttributedString。我正在使用NSTextAttachment在文本中嵌入图像。这是个坏主意吗?目前滚动性能似乎不错,但我不确定是否有更好的方法?将所有NSMutableAttributedString缓存在NSMutableDictionary中对于第二次滚动会更好吗?使用cellForRowAtIndexPath也可以将相同的问题应用于UITableview。代码:-(UICollectionViewCell*)collectionView:(UIColle

ios - 更改不同范围的字体时 NSMutableAttributedString 崩溃

因此,我尝试更改NSMutableAttributedString的颜色,但当我尝试添加多个范围时,我不断收到越界异常错误(见下文)。另一方面,如果我只做从0到totalLength-1的单个范围,则没有问题。我不知道为什么会这样。我的代码如下:NSString*testString=@"Thisismyteststringforthisexample";NSMutableAttributedString*attribString=[[NSMutableAttributedStringalloc]initWithString:testString];inttotalLength=[pl

ios - NSMutableAttributedString 转换为字符串,同时保持格式

我想为我的TableView分配一个标题标题,但我希望标题分为两行。第二行的字体应小于第一行。我正在尝试使用NSMutableAttributedString,但在方法中:-(NSString*)tableView:(UITableView*)tableViewtitleForHeaderInSection:(NSInteger)section但它返回一个NSString而不是NSMutableAttributedString。有什么方法可以将NSMutableAttributedString转换为NSString,同时保持字符串的格式?这是我的代码:-(NSString*)table

ios - 如何在 Objective-C 中更改 NSMutableAttributedString 的大小写?

我有一个包含小写字母值的NSMutableAttributedString。我需要将所有小写字母转换为大写字母。我们可以使用uppercaseString作为普通字符串来解决这个问题:[stringuppercaseString];如何更改NSMutableAttributedString的大小写?谢谢! 最佳答案 希望下面的代码片段能帮到你NSMutableAttributedString*linkString=[[NSMutableAttributedStringalloc]initWithString:@"Google"];N

ios - NSMutableAttributedString 在具有特定范围的 tableviewcell 中不起作用

我关注了thisquestion但没有解决我的问题。我在ViewController中有一个tableview,tableviewcell有一个标签。我想用NSStrikethroughStyleAttributeName设置attributedString。如果我将完整的字符串设置为删除线,它会起作用但是如果我设置为部分字符串,它就不起作用。BelowcodeforsuccessresultletstrOriginalPrice="myprice"letstrdiscountedPrice="discountedprice"letstrPrice=strOriginalPrice+"