2013-10-01 8 views
7

अभी मैंमैं एनएसटीएक्स्ट एकाधिक छाया कैसे दे सकता हूं?

NSShadow *textShadow = [NSShadow new]; 
textShadow.shadowBlurRadius = 5; 
textShadow.shadowColor = [[NSColor whiteColor] colorWithAlphaComponent:.5]; 

[self addAttribute:NSShadowAttributeName value:textShadow range:NSMakeRange(0, self.length)]; 

उपयोग कर रहा हूँ एक NSTextStorage से पाठ एक छाया देने के लिए। लेकिन मैं एक से अधिक छाया लागू करना चाहता हूं, और एक और NSShadowAttributeName जोड़ना सिर्फ पिछले मान को ओवरराइट करता हूं।

मैं एक से अधिक छाया कैसे जोड़ सकता हूं? क्या यह CGContextSetShadowWithColor के साथ किया जा सकता है?

+0

क्या आप टेक्स्टव्यू के अंदर स्ट्रिंग करने के लिए कुछ रंग ढूंढ रहे हैं ?? –

+0

नहीं। मैं बस पाठ में एक से अधिक ड्रॉप छाया लागू करना चाहता हूं। – zakdances

+0

यह gr8 होगा, अगर आप आउटपुट नमूना पेस्ट कर सकते हैं –

उत्तर

3

सुनिश्चित नहीं है कि कृपया अपने टेक्स्टव्यू के लिए नीचे दिए गए कोड को आज़माएं। जब आप TextView अंदर स्ट्रिंग लिखने यह है कि इतना सीमा चुनते हैं और यह रंग खींचता है उस के आधार पर होगी: -

-(IBAction)createNewTabView:(id)sender 
{ 
    NSString *allTheText =[tv string]; 
    NSArray *lines = [allTheText componentsSeparatedByString:@"\n"]; 
    NSString *str=[[NSString alloc]init]; 
    NSMutableAttributedString *attr; 
    BOOL isNext=YES; 
    [tv setString:@""]; 
    for (str in lines) 
    { 
     attr=[[NSMutableAttributedString alloc]initWithString:str]; 
     if ([str length] > 0) 
     { 

     NSRange range=NSMakeRange(0, [str length]); 
     [attr addAttribute:NSBackgroundColorAttributeName value:[NSColor greenColor] range:range]; 
     [tv .textStorage appendAttributedString:attr]; 
      isNext=YES; 
     } 
     else 
     { 
      NSString *[email protected]"\n"; 
      NSAttributedString *attr=[[NSAttributedString alloc]initWithString:str]; 
      [tv .textStorage appendAttributedString:attr]; 
      isNext=NO; 
     } 
     if (isNext==YES) 
     { 
      NSString *[email protected]"\n"; 
      NSAttributedString *attr=[[NSAttributedString alloc]initWithString:str]; 
      [tv .textStorage appendAttributedString:attr]; 

     } 

    } 
    } 
+0

यह पृष्ठभूमि रंग नहीं है जो मैं चाहता हूं। मैं एक से अधिक ड्रॉप छाया ('NSShadowAttributeName') जोड़ना चाहता हूं। – zakdances

2

मैं "गुफा" दृष्टिकोण सुझाव है। डुप्लिकेट छाया प्राप्त करने का प्रयास करने के बजाय, डुप्लिकेट टेक्स्ट का उपयोग करें, लेकिन इनमें से एक का रंग स्पष्ट रंग पर सेट है, और उन्हें अलग ड्रॉपशैड दें।

  • दो अयस्क अधिक टेक्स्ट को ठीक उसी पंक्ति में बनाते हैं।
  • अपने सबसे "असली" टेक्स्ट रंग को आगे बढ़ाएं।
  • अन्य पाठ का स्पष्ट रंग बनाएं।
  • प्रत्येक प्रकार के टेक्स्ट के लिए एक प्रकार का छाया सेट करें।

यदि आप इसे कई बार उपयोग करने जा रहे हैं, तो आपको यह कक्षा स्वचालित करने में सक्षम होना चाहिए।

यह मैं क्या मिल गया का एक नमूना है:

enter image description here

oh-- अगर आप अतिरिक्त पाठ के अपने पाठ गहरा/bolder आपकी अपेक्षा से दिखाई देगा नहीं बनाते हैं।

+0

दुर्भाग्य से, पाठ रंग की अस्पष्टता को बदलने से छाया की अस्पष्टता भी प्रभावित होती है। साथ ही, एकाधिक ओवरलैपिंग टेक्स्ट दृश्यों को प्रस्तुत करना बहुत अक्षम है, खासकर जब आप बड़े, बहु-पृष्ठ दस्तावेज़ों के साथ काम कर रहे हों। – zakdances

संबंधित मुद्दे