이의 내가이 있다고 가정 해 봅시다 색깔. 그러나 두 번째 "ㅋ"는 괄호로 묶고 작은 크기와 회색을 사용합니다. 이 일을 어떻게 하죠? 심지어 가능할까요?다른 글꼴 스타일
0
A
답변
0
NSMutableAttributedString을 사용하려고합니다.
- setAttributes:range:
을 호출하기 만하면 모든 사용자 문자열을 연결하고 각 하위 문자열에 원하는 특성을 표시 할 수 있습니다.
0
NSString을 사용하면 특정 스타일을 사용할 수 없습니다. 문자열에 스타일/속성이 필요하면 NSAttributedString을 사용해야합니다.
0
바로 지금은 NSString
개의 개체 만 저장합니다. NSString 그것에 연결된 글꼴이 없습니다. 당신이 글꼴 정보를 유지하려면 - 당신은 NSAttributedString
클래스에서 좀 걸릴 수 있습니다 - https://developer.apple.com/Library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSAttributedString_Class/index.html
그래서 코드는 같을 것이다
self.items = @[
[[NSAttributedString alloc] initWithString: @"bla" attributes: @{
NSFontAttributeName: [UIFont systemFontOfSize: 12.0],
NSForegroundColorAttributeName: [UIColor blackColor]
}],
[[NSAttributedString alloc] initWithString: @"bla" attributes: @{
NSFontAttributeName: [UIFont systemFontOfSize: 14.0],
NSForegroundColorAttributeName: [UIColor grayColor]
}]
];
0
코드 아래에보십시오 : -
NSArray *yourArr= @[@"blah",
@"blah",
@"blah (blah)",
@"blah",
@"blah"];
for (NSString *word in yourArr)
{
if ([word isEqualToString:@"blah (blah)"])
{
[yourAtt appendAttributedString:[[NSAttributedString alloc]initWithString:[word componentsSeparatedByString:@" "][0] attributes:@{NSFontAttributeName:[NSFont boldSystemFontOfSize:18]}]];
[yourAtt appendAttributedString:[[NSAttributedString alloc]initWithString:@" "]];
[yourAtt appendAttributedString:[[NSAttributedString alloc]initWithString:[word componentsSeparatedByString:@" "][1] attributes:@{NSFontAttributeName:[NSFont boldSystemFontOfSize:14],NSForegroundColorAttributeName:[NSColor grayColor]}]];
}
else
{
[yourAtt appendAttributedString:[[NSAttributedString alloc]initWithString:word]];
}
[yourAtt appendAttributedString:[[NSAttributedString alloc]initWithString:@",\n"]];
}
self.yourAttStr=yourAtt;
관련 문제
- 1. 글꼴 아이콘에 대한 다른 스타일
- 2. 정렬되지 않은 목록 내의 다른 글꼴 스타일
- 3. 단일 FormView에서 다른 글꼴 스타일 구현 C#
- 4. 맞춤 글꼴 스타일 문제
- 5. fallback-fonts 전용 글꼴 스타일/글꼴 가중치?
- 6. 특정 CSS 글꼴 스타일
- 7. C에서 글꼴 스타일 변경 #
- 8. 사용자 정의 글꼴 스타일
- 9. 다중 글꼴 스타일
- 10. 글꼴 스타일 순서
- 11. System.Drawing없이 글꼴 스타일 설정
- 12. CSS : 글꼴 - 가족 스타일
- 13. NSMenuItem가 굵은 글꼴 스타일
- 14. Tkinter 글꼴 스타일
- 15. 초기화 스타일 글꼴 여러 스타일 사용
- 16. FPDF - 결합 된 글꼴 스타일
- 17. WPF, 여러 컨트롤의 글꼴 스타일
- 18. 로드 구글 글꼴 스타일 시트
- 19. 글꼴 내 CSS 스타일 시트에서
- 20. 윈도우 폰 7 글꼴 스타일
- 21. vb.net에서 RichTextBox의 글꼴 스타일 조정
- 22. Sidr.js 글꼴 굉장 클래스 스타일
- 23. iOS의 유로 스타일 글꼴 지원?
- 24. TCPDF에 frutiger 글꼴 스타일 포함
- 25. 안드로이드 키보드의 글꼴 스타일 변경
- 26. Label Docorator의 글꼴 스타일 변경
- 27. RTF 문서의 글꼴 스타일 설정
- 28. GWT 자바 글꼴 스타일 설정
- 29. MouseEnter 이벤트의 TBitBtn 글꼴 스타일
- 30. Android에서 기본 글꼴 스타일 사용