असल में मुझे UILabel
पसंद है। वे मीठे हैं। अब मुझे UITextView
पर जाना पड़ा क्योंकि UILabel
शीर्ष पर लंबवत पाठ को संरेखित नहीं कर रहा है। अरे नहीं। एक चीज जिसकी मुझे ज़रूरत है वह एक पाठ छाया है। UILabel
में यह है। UITextView
ऐसा नहीं लगता है। लेकिन मुझे लगता है कि लड़का सिर्फ उसी अंतर्निहित UIKit
NSString
जोड़ों का उपयोग करता है ?? हो सकता है कि किसी के पास पहले से ही उस समस्या का समाधान हो? मैं क्या लिखूंगा?UITextView पर टेक्स्ट छाया कैसे लागू करें?
उत्तर
text.layer.shadowColor = [[UIColor whiteColor] CGColor];
text.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
text.layer.shadowOpacity = 1.0f;
text.layer.shadowRadius = 1.0f;
और भूल जाते हैं शीर्ष को जोड़ने के लिए नहीं है:
#import <QuartzCore/QuartzCore.h>
सही उत्तर चिह्नित उत्तर मुझे लगता है कि यह गन्दा और आम तौर पर खराब रूप है। – averydev
मेरी इच्छा है कि मैं इसे आगे चिह्नित कर सकूं - यह UITextView में छाया जोड़ने का उचित तरीका है। दूसरी विधि बहुत भारी है और यह बिल्कुल नहीं है कि UITextView के बहुत छोटे उपयोगों के अलावा किसी अन्य चीज़ के लिए किया जाना चाहिए। –
अजीब व्यवहार: यह दृष्टिकोण टेक्स्ट को छाया में जोड़ता है, न कि uitextview बॉक्स में। मैं बॉक्स में छाया को छाया में नहीं जोड़ना चाहता हूं। –
साथ जवाब text.layer.shadowColor
पूरे TextView के लिए छाया कहते हैं, शायद यह काम करता है, लेकिन यह न केवल पाठ के लिए छाया जोड़ता है।
सही जवाब है:
CALayer *textLayer = ((CALayer *)[textView.layer.sublayers objectAtIndex:0]);
textLayer.shadowColor = [UIColor whiteColor].CGColor;
textLayer.shadowOffset = CGSizeMake(0.0f, 1.0f);
textLayer.shadowOpacity = 1.0f;
textLayer.shadowRadius = 1.0f;
काम करने के लिए यह सही तरीका है संपादन योग्य टेक्स्टव्यू – zszen
यह प्रयोग कर रहे हैं आईओएस के संस्करण पर निर्भर करता है। आईओएस 6 के साथ शुरुआत एक ही छाया समर्थित है, आप इसे एनएसएट्रिब्रिटेड स्ट्रिंग पर एक विशेषता के रूप में सेट करते हैं जिसे आपने लेबल पर सेट किया था।
आईओएस में 6 + उपयोग के लिए जिम्मेदार ठहराया पाठ
NSShadow * shadow = [[NSShadow alloc] init];
shadow.shadowColor = [UIColor blackColor];
shadow.shadowOffset = CGSizeMake(2, 2);
NSDictionary * textAttributes =
@{ NSForegroundColorAttributeName : [UIColor blueColor],
NSShadowAttributeName : shadow,
NSFontAttributeName : [UIFont boldSystemFontOfSize:20] };
textView.attributedText = [[NSAttributedString alloc] initWithString:@"Hello"
attributes:textAttributes];
दुख की बात यह है कि इसे संपादित नहीं किया जा सकता – zszen
स्विफ्ट 3
let textView = UITextView(frame: view.frame)
textView.font = UIFont(name: "Helvetica", size: 64.0)
textView.textColor = .red
textView.text = "Hello World"
textView.layer.shadowColor = UIColor.black.cgColor
textView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
textView.layer.shadowOpacity = 1.0
textView.layer.shadowRadius = 2.0
textView.layer.backgroundColor = UIColor.clear.cgColor
स्विफ्ट 2,3
let textView = UITextView(frame: view.frame)
textView.font = UIFont(name: "Helvetica", size: 64.0)
textView.textColor = UIColor.redColor()
textView.text = "Hello World"
textView.layer.shadowColor = UIColor.blackColor().CGColor
textView.layer.shadowOffset = CGSize(width: 2.0, height: 2.0)
textView.layer.shadowOpacity = 1.0
textView.layer.shadowRadius = 2.0
textView.layer.backgroundColor = UIColor.clearColor().CGColor
यह स्विफ्ट उदाहरण पाठ में छाया जोड़ने के लिए जिम्मेदार ठहराया स्ट्रिंग विधि का उपयोग करता। स्विफ्ट में जिम्मेदार तारों के बारे में अधिक जानकारी के लिए this answer देखें। यह विधि (layer method का उपयोग करने के विरोध में) यदि आप चाहें तो छाया की एक श्रृंखला पर छाया सेट करने के लिए लचीलापन देता है।
// Create a string
let myString = "Shadow"
// Create a shadow
let myShadow = NSShadow()
myShadow.shadowBlurRadius = 3
myShadow.shadowOffset = CGSize(width: 3, height: 3)
myShadow.shadowColor = UIColor.gray
// Create an attribute from the shadow
let myAttribute = [ NSAttributedStringKey.shadow: myShadow ]
// Add the attribute to the string
let myAttrString = NSAttributedString(string: myString, attributes: myAttribute)
// set the attributed text on a label
myLabel.attributedText = myAttrString // can also use with UITextView
स्विफ्ट 4
यह मेरे लिए बहुत अच्छा काम करता है। धन्यवाद। – adev
- 1. टेक्स्ट छाया
- 2. सभी चार किनारों पर बॉक्स-छाया कैसे लागू करें?
- 3. टेक्स्ट-छाया
- 4. UITextView पर कीबोर्ड को अक्षम कैसे करें?
- 5. UITextView रिच टेक्स्ट?
- 6. केवल सीमा-शीर्ष पर ड्रॉप छाया लागू करें?
- 7. UITextView पेजिंग सक्षम टेक्स्ट
- 8. UITextView
- 9. Google क्रोम टेक्स्ट छाया प्रतिपादन
- 10. UITextView
- 11. UITextView
- 12. UITextView
- 13. टेक्स्ट इनपुट की आंतरिक छाया हटाएं
- 14. UITextView
- 15. UITextView
- 16. UITextView
- 17. UITextView
- 18. UITextView
- 19. उसी तत्व पर एकाधिक प्रभाव कैसे लागू करें
- 20. UITextView
- 21. UITextView में मार्जिन कैसे सेट करें?
- 22. लागू करने छाया अपने पाठ धुँधली बनाता
- 23. आईफोन पर UITextView की स्क्रॉल स्थिति रीफ्रेश करें
- 24. UITextView पर लंबी प्रेस को कैसे रोकें?
- 25. UITextView
- 26. मैं UITextView
- 27. UITextview
- 28. UITextView
- 29. आप UITextView में टेक्स्ट का रंग कैसे बदलते हैं?
- 30. UITextView की टेक्स्ट लम्बाई कैसे तय की जा सकती है?
के लिए अपडेट किया गया मुझे लगता है कि आप adjwilli जवाब को स्वीकार करना चाहिए, क्योंकि यह आसान चींटी है मुझे लगता है कि सबसे सहमत होंगे कि यह यह करने के लिए सही तरीका है। – Lukas