-(UITableViewCell*) makeLikeCell
{
// Load the top-level objects from the custom cell XIB.
NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"SpotlightLikesTableViewCell" owner: self options: nil];
// Grab a pointer to the first object (presumably the custom cell, as that's all the XIB should contain).
UITableViewCell *cell = [topLevelObjects objectAtIndex:0];
NSString *likeText = [likesAndComments objectAtIndex: kLikeRow];
TTTAttributedLabel *likeLabel = [[[TTTAttributedLabel alloc] initWithFrame:CGRectZero] autorelease];
likeLabel = (TTTAttributedLabel*) [cell viewWithTag: kCaptionTag];
likeLabel.textColor = [UIColor blueColor];
likeLabel.lineBreakMode = UILineBreakModeWordWrap;
[likeLabel setFont: [UIFont fontWithName: @"Helvetica Neue" size: …Run Code Online (Sandbox Code Playgroud) 我正在使用我使用NSAttributedString格式化的数据填充NSOutlineView.到目前为止,我已经格式化了文本字体,大小和颜色.我的问题是,选择行时前景色不会改变.如果您在Interface Builder上创建NSTextFieldCell并将颜色设置为disabledControlTextColor,它可以正常工作:未选中时显示为灰色,选择白色时,当我以编程方式将此颜色设置为属性字符串定义时,它始终显示为灰色.
NSMutableAttributedString *result = [[[NSMutableAttributedString alloc] initWithString:value] autorelease];
NSDictionary *attributes = [[NSDictionary dictionaryWithObjectsAndKeys:
[NSFont systemFontOfSize:[NSFont systemFontSize] -1], NSFontAttributeName,
[NSColor disabledControlTextColor], NSForegroundColorAttributeName, nil] retain];
[result addAttributes:attributes range:[value rangeOfString:value]];
Run Code Online (Sandbox Code Playgroud)
提前致谢.
我正在尝试向基于视图的NSOutlineView中的单元格添加一些格式。无论我尝试什么,都将以我指定的任何格式呈现文本。这是我目前的方法:
NSMutableAttributedString *versionString = [[NSMutableAttributedString alloc]
initWithString:myString];
[versionString addAttribute:NSForegroundColorAttributeName
value:[NSColor redColor] range:NSMakeRange(0, 3)];
NSTableCellView result = [outlineView makeViewWithIdentifier:@"DataCell"
owner:self];
result.textField.allowsEditingTextAttributes = YES;
result.textField.attributedStringValue = versionString;
Run Code Online (Sandbox Code Playgroud)
是否无法在NSOutlineView和标准NSTextField中呈现属性字符串?
cocoa objective-c nsoutlineview nstableview nsattributedstring
我正在使用iOS的富文本编辑器,使用UITextView和NSAttributedString.它的功能与传统的相似(即选择区域,单击按钮,并将该效果应用于该区域,同时保留文本上的任何其他属性.
不幸的是NSAttributedString,并非所有这些都可以独立调整.其中一些(至少是粗体,字体和字体大小)都需要传递a UIFont,这将为该区域设置所有这些属性(即使您只想设置一个).看作单个区域可能包括多个面和大小,这将导致天真的方法打破了许多现有的格式.
有没有推荐的方法来实现这一目标?我认为我唯一的选择是遍历我想要应用它的区域的属性,将其分组为具有相同其他字体属性的块,然后单独应用于每个块.
我有一个NSMutableAttributedString,如"鲍勃喜欢你的照片".
我想知道我是否可以为"Bob"和"picture"添加两个不同的点击事件.理想情况下,点击"Bob"将呈现具有Bob的配置文件的新视图控制器,并且点击"图片"将呈现具有该图片的新视图控制器.我可以用NSMutableAttributedString做到这一点吗?
我想创建一个显示标题,子标题,嵌入图像和常规文本(有点类似于维基百科样式页面)的显示.我的标题,子标题,图像和常规文本都是字符串.我理解AttributedString是实现我想要的格式的最佳方式.我无法弄清楚的是如何从我之前存在的字符串创建AttributedString.
displayText = [[NSMutableAttributedString alloc] initWithAttributedString:@"%@ \n %d - %@", self.currentInstance.name, self.currentInstance.number, self.currentInstance.image];
textView.attributedText = displayText;
Run Code Online (Sandbox Code Playgroud)
我是新人,所以我确信这是基本的我做错了.我感谢任何帮助.
我想为表格视图分配标题标题,但我希望标题分成两行。第二行应具有比顶行小的字体。
我正在尝试使用NSMutableAttributedString,但是在方法中:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
Run Code Online (Sandbox Code Playgroud)
但它返回NSString而不是NSMutableAttributedString。
有什么办法,我可以转换NSMutableAttributedString到NSString同时保持字符串格式化?
这是我的代码:
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
NSString *title = @"";
title = @"Top Line \n";
if(_favouriteLocations.count == 0){
title = [title stringByAppendingString:@"Smaller font Bottom Line"];
}
NSMutableAttributedString *attString =[[NSMutableAttributedString alloc] initWithString:title];
NSRange range = [title rangeOfString:@"Smaller"];
[attString setAttributes:@{NSFontAttributeName:@"8"} range:NSMakeRange(range.location, title.length - range.location)];
NSLog(@"%@", attString);
title = [attString string];
return title;
}
Run Code Online (Sandbox Code Playgroud) NSTextAttachment锁定图像在边缘切断,但当线条没有在边缘处断开时,可以看到锁定图标.我希望图标移动到下一行,就像一个单词移动到下一行.
以下是示例:
NSTextAttachment *attachment = [[NSTextAttachment alloc] init];
attachment.image = [UIImage imageNamed:@"lock.png"];
NSString *stringHeadline = @"This is a example sample sentence. Why I do";
NSAttributedString *attachmentLock = [NSAttributedString attributedStringWithAttachment:attachment];
NSAttributedString *myText = [[NSMutableAttributedString alloc] initWithString:stringHeadline];
NSMutableAttributedString *lockString = [[NSMutableAttributedString alloc] initWithAttributedString:myText];
[lockString appendAttributedString:attachmentLock];
lblHeadline.attributedText = lockString;
[lblHeadline sizeToFit];
Run Code Online (Sandbox Code Playgroud)


当边缘附近的文本时,锁图标丢失了.
在使用Swift 3.2的macOS项目中,我正在尝试设置UITextView的前景色.
let placeHolderTitleString: NSAttributedString = NSAttributedString(string: "Enter text here", attributes: [NSAttributedStringKey.foregroundColor : NSColor.gray]) // error
Run Code Online (Sandbox Code Playgroud)
我得到的错误是这样的:
类型'NSAttributedStringKey'(又名'NSString')没有成员'foregroundColor'
相同的代码在Swift 4.0项目中工作正常.
我试图根据我发现的iOS Swift 4转换错误的一些答案修改代码- NSAttributedStringKey:任何但我继续得到错误.有没有办法解决这个问题,而无需将项目更新到Swift 4?
遇到一些删除线才能正常工作的问题。目前,我正在执行以下操作:
theString.addAttributes([
NSAttributedStringKey.strikethroughStyle: NSUnderlineStyle.styleSingle.rawValue,
NSAttributedStringKey.strikethroughColor: UIColor.white
], range: NSMakeRange(0, 1))
Run Code Online (Sandbox Code Playgroud)
它没有显示任何形式的删除线。有任何想法吗?我似乎找不到任何有效的方法。
ios ×5
objective-c ×5
cocoa ×2
iphone ×2
macos ×2
swift ×2
core-text ×1
nscell ×1
nsstring ×1
nstableview ×1
uitableview ×1
xcode ×1