है, मैं एक NSTextView [1] में HTML का सबसेट संपादित कर रहा हूं और मैं < घंटा > टैग अनुकरण करना चाहता हूं।NSTextAttachmentCell एक मील उच्च
मुझे पता चला है कि ऐसा करने का तरीका NSTextAttachment और एक कस्टम NSTextAttachmentCell के साथ है, और इसमें कोड संलग्नक और सेल डालने के लिए लिखा गया है। समस्या यह है कि सेल के नीचे एक खाली मात्रा में रिक्त स्थान है।
यह स्थान सेल का हिस्सा नहीं है-अगर मैं सेल के पूरे क्षेत्र को लाल रंग देता हूं, तो यह बिल्कुल सही आकार है, लेकिन टेक्स्ट व्यू लाल रंग से बहुत नीचे टेक्स्ट की अगली पंक्ति डाल रहा है। यह राशि इस बात पर निर्भर करती है कि से ऊपर कितना टेक्स्ट है; दुर्भाग्य से, मैं लंबे दस्तावेजों के साथ काम कर रहा हूं जहां < एचआर > टैग महत्वपूर्ण हैं, और इससे ऐप के साथ बड़ी समस्याएं आती हैं।
क्या बिल्ली चल रहा है?
मेरे सेल उपवर्ग के पैसे भागों:
- (NSRect)cellFrameForTextContainer:(NSTextContainer *)textContainer
proposedLineFragment:(NSRect)lineFrag glyphPosition:(NSPoint)position
characterIndex:(NSUInteger)charIndex {
lineFrag.size.width = textContainer.containerSize.width;
lineFrag.size.height = topMargin + TsStyleBaseFontSize *
heightFontSizeMultiplier + bottomMargin;
return lineFrag;
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView
characterIndex:(NSUInteger)charIndex
layoutManager:(NSLayoutManager *)layoutManager {
NSRect frame = cellFrame;
frame.size.height -= bottomMargin;
frame.size.height -= topMargin;
frame.origin.y += topMargin;
frame.size.width *= widthPercentage;
frame.origin.x += (cellFrame.size.width - frame.size.width)/2;
[color set];
NSRectFill(frame);
}
[1] मैंने कोशिश की isEditable सेट और मार्कअप यह उत्पादन के साथ एक WebView था unusably गंदा-विशेष रूप से, मैं नहीं एक मिल सकता है < पी > टैग में अच्छी तरह से पाठ लपेटने का तरीका।
- (void)insertHorizontalRule:(id)sender {
NSAttributedString * rule = [TsPage newHorizontalRuleAttributedStringWithStylebook:self.book.stylebook];
NSUInteger loc = self.textView.rangeForUserTextChange.location;
if(loc == NSNotFound) {
NSBeep();
return;
}
if(loc > 0 && [self.textView.textStorage.string characterAtIndex:loc - 1] != '\n') {
NSMutableAttributedString * workspace = rule.mutableCopy;
[workspace.mutableString insertString:@"\n" atIndex:0];
rule = workspace;
}
if([self.textView shouldChangeTextInRange:self.textView.rangeForUserTextChange replacementString:rule.string]) {
[self.textView.textStorage beginEditing];
[self.textView.textStorage replaceCharactersInRange:self.textView.rangeForUserTextChange withAttributedString:rule];
[self.textView.textStorage endEditing];
[self.textView didChangeText];
}
[self.textView scrollRangeToVisible:self.textView.rangeForUserTextChange];
[self reloadPreview:sender];
}
और TsPage में विधि है कि लगाव स्ट्रिंग निर्माण करती है:
कोड कि क्षैतिज नियम लगाव सम्मिलित करता है के लिए रोब Keniger के अनुरोध का जवाब देने के
+ (NSAttributedString *)newHorizontalRuleAttributedStringWithStylebook:(TsStylebook*)stylebook {
TsHorizontalRuleCell * cell = [[TsHorizontalRuleCell alloc] initTextCell:@"—"];
cell.widthPercentage = 0.33;
cell.heightFontSizeMultiplier = 0.25;
cell.topMargin = 12.0;
cell.bottomMargin = 12.0;
cell.color = [NSColor blackColor];
NSTextAttachment * attachment = [[NSTextAttachment alloc] initWithFileWrapper:nil];
attachment.attachmentCell = cell;
cell.attachment = attachment;
NSAttributedString * attachmentString = [NSAttributedString attributedStringWithAttachment:attachment];
NSMutableAttributedString * str = [[NSMutableAttributedString alloc] initWithString:@""];
[str appendAttributedString:attachmentString];
[str.mutableString appendString:@"\n"];
return str;
}
आप कर सकते हैं कोड को पोस्ट करें कि आप अपने 'NSTextView' में टेक्स्ट अटैचमेंट कैसे डाल रहे हैं? –
रोब, मैंने वह कोड जोड़ा है जिसे आप देखना चाहते थे। इसे देखने के लिए धन्यवाद! –