문제

UITextView에서 다음 HTML을 가지고 있고 UITextView

에 렌더링하고자합니다.

메모

에 대한 내 몸입니다.
<a href="/arc/item/21">food item - more item stuff</a>;`
.

ADD : 현재 파란색으로 표시되고 밑줄이 그어져 있고 클릭 할 수 없습니다.나는 그것을 굵게 표시하고 클릭 할 수 없게하고 싶습니다.나는 linkTextAttributes와 관련하여 문서를 읽었지만, 이것을 사용하지 않고, 그것은 나머지는 조금 그 이상이며, 이것을 조작하는 쉬운 방법을 보지 못합니다.위의 링크를 굵게 표시하고 검은 색으로 렌더링하고 폐색 할 수없는 자연을 유지합니까?

도움이 되었습니까?

해결책

update ( uitextview의 linktextattributes ) )

self.testTextView.editable = NO;
self.testTextView.selectable = YES;
self.testTextView.userInteractionEnabled = NO;  // workaround to disable link - CAUTION: it also disables scrolling of UITextView content
self.testTextView.dataDetectorTypes = UIDataDetectorTypeLink;
self.testTextView.linkTextAttributes = @{NSFontAttributeName : [UIFont boldSystemFontOfSize:14.0f], // NOT WORKING !?
                                         NSForegroundColorAttributeName : [UIColor redColor]};

...

self.testTextView.text = @"Lorem ipsum http://www.apple.com Lorem ipsum";
.

코멘트에서 볼 수 있듯이 색상 속성이 예상대로 작동하지만 LinkTextAttributes에 새 글꼴을 설정할 수 없었습니다.

컬러 속성 또는 다른 텍스트 속성을 벗어나는 경우 URL을 스타일링하고 uItextView 스크롤을 걱정할 필요가 없으면 해결 방법이 될 수 있습니다.


이전 (대체 솔루션)

스토리 보드 / xib을 사용하는 경우 uitextView에 대해 탐지 -> 링크 을 선택 해제했는지 확인하십시오. 컨테이너 글꼴을 일부 굵은 글꼴로 설정하여 링크 굵게 표시 할 수 있습니다. 하나의 문자열 객체에서 다른 텍스트 / 글꼴 스타일을 지원하려는 경우 nsattributedString 또는 nsmutableAttributedString 을 정말로 찾아야합니다.

참조 : https : //developer.apple.com/library/ios/documentation/cocoa//reference/foundation/classes/nsattributedstring_class/reference/reference.html .

예제 :

UIFont *linkFont = [UIFont fontWithName:@"SomeBoldTypeface" size:12];
NSString *link = @"food item - more item stuff";

NSMutableAttributedString *someString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"is my body for the note %@; let me ad", link]];
[someString addAttribute:NSFontAttributeName value:linkFont range:NSMakeRange(24, link.length)];

UITextView *textView = [[UITextView alloc] init];
textView.attributedText = someString;
...
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top