我试图为UITextView
NSMutableAttributedString
添加一个合理的文本,NSMutableAttributedString
由不同的NSAttributedString
组成,因为我需要粗体和常规字体,所以我添加了不同的NSString
,这是我的NSMutableAttributedString
:
NSAttributedString *one = [[NSAttributedString alloc] initWithString:@"abc"
attributes:boldDict];
NSAttributedString *two = [[NSAttributedString alloc] initWithString:@" def"
attributes:regularDict];
NSAttributedString *three = [[NSAttributedString alloc] initWithString:@" ghi"
attributes:boldDict];
NSMutableAttributedString *string =
[[NSMutableAttributedString alloc] initWithAttributedString:one];
[string appendAttributedString:two];
[string appendAttributedString:three];
我试过这个:
[self.text_view setTextAlignment:NSTextAlignmentJustified]
和此:
NSMutableParagraphStyle *paragraphStyles = [[NSMutableParagraphStyle alloc] init];
paragraphStyles.alignment = NSTextAlignmentJustified;
Dictionary *attributes = @{NSParagraphStyleAttributeName: paragraphStyles};
并将其应用于NSMutableAttributedString,但都不起作用。我怎么做?
答案 0 :(得分:1)
我通过为NSAttributedString指定透明背景颜色来解决同样的问题。
看起来像UILabel代码中的一个错误,它应该像NSString一样呈现简单的NSAttributedString。
Xamarin.iOS示例:
struct node* insert(struct node* node, int data) {
// 1. If the tree is empty, return a new, single node
if (node == NULL) {
return(newNode(data));
}
else {
// 2. Otherwise, recur down the tree
if (data <= node->data) node->left = insert(node->left, data);
else node->right = insert(node->right, data);
return(node); // return the (unchanged) node pointer-->THIS LINE
}
}