Eigentlich liebe ich UILabel
. Sie sind süß. Jetzt musste ich zu UITextView
gehen, weil UILabel
Text nicht vertikal nach oben ausrichtet. Verdammt. Eine Sache, die ich wirklich brauche, ist ein Textschatten. UILabel
hat es. UITextView
scheint es nicht zu haben. Aber ich denke, dass dieser Typ nur die gleichen zugrunde liegenden UIKit
NSString
Ergänzungen verwendet ?? Vielleicht hat jemand schon eine Lösung für dieses Problem? Was würde ich überschreiben?Wie man Textschatten auf UITextView anwendet?
Antwort
text.layer.shadowColor = [[UIColor whiteColor] CGColor];
text.layer.shadowOffset = CGSizeMake(1.0f, 1.0f);
text.layer.shadowOpacity = 1.0f;
text.layer.shadowRadius = 1.0f;
Und vergessen Sie nicht oben zu addieren:
#import <QuartzCore/QuartzCore.h>
Die Antwort, die richtig markiert wird, wird funktionieren, nehme ich an, aber ihre unordentliche und allgemein schlechte Form. – averydev
Ich wünschte, ich könnte dies weiter markieren - das ist die geeignete Möglichkeit, einen Schatten zu einem UITextView hinzuzufügen. Die andere Methode ist sehr schwer und nicht die Art und Weise, die für alles andere als nur triviale Anwendungen von UITextView getan werden sollte. –
seltsames Verhalten: Dieser Ansatz fügt dem Text selbst Schatten hinzu, nicht dem Feld uitextview. Ich möchte der Box Schatten hinzufügen, nicht dem Text. –
Die Antwort mit
text.layer.shadowColor
Schatten auf ganze Textview fügt hinzu: vielleicht funktioniert es, aber es fügt Schatten nicht nur dem Text hinzu.
Die richtige Antwort lautet:
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;
Es ist der richtige Weg mit editierbaren Textview – zszen
Es ist auf der iOS-Version ab, die Sie verwenden. Ab iOS 6 wird ein einzelner Schatten unterstützt, den Sie als Attribut für einen NSAtributedString festlegen, den Sie dann auf dem Label festlegen.
Ios 6+ Verwendung zugeschrieben Text
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];
Leider kann es nicht bearbeitet werden – zszen
Swift 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
Swift 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
Dieses Swift Beispiel verwendet die zugeschrieben String-Methode Schatten der Zugabe zum Text. Weitere Informationen zu attributierten Strings in Swift finden Sie unter this answer. Diese Methode (im Gegensatz zur Verwendung der layer method) gibt Ihnen die Flexibilität, den Schatten auf eine Reihe von Text festzulegen, wenn Sie möchten.
// 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
für Swift 4
Dies funktionierte gut für mich. Vielen Dank. – adev
- 1. Verstehen, wie man anwendet und nicht anwendet
- 2. Wie man Themen auf winform Titelleiste anwendet
- 3. Wie man einen Kleinbuchstabenfilter auf GridView anwendet?
- 4. Wie man jQuery auf Meteor.js anwendet
- 5. Rails: Wie man Hintergrundfarbe auf Körper anwendet
- 6. Wie man Filter auf Nachrüstungsanfrage anwendet?
- 7. Wie man Django-Patches anwendet
- 8. Wie man highchart Lizenz anwendet
- 9. wie man eine mittelschwere Funktion parallel anwendet
- 10. Wie man OWASP in WCF anwendet
- 11. Wie man einen Django-Patch anwendet?
- 12. Wie man Zeilenspanne in tabellarischer Darstellung anwendet?
- 13. wie man DRM für iPhone Anwendungen anwendet
- 14. Angular 2. Wie man orderBy anwendet?
- 15. Wie man mehrere Transformationen in Swift anwendet
- 16. Wie man einen Patch auf ein Java-Projekt anwendet?
- 17. Wie man Ränder auf alle Zellen anwendet, kein Bereich !
- 18. Verstehen, wie man einen Slicer auf einen Prozentsatz anwendet
- 19. Wie man eine Transformationsmatrix auf einen Vektor in SceneKit anwendet
- 20. Wie man CSS auf HTML body element anwendet?
- 21. Wie man benutzerdefinierte Spaltenreihenfolge auf Pandas Boxplot anwendet?
- 22. Wie man eine .pp auf einen Knoten anwendet
- 23. Wie man Effekte auf ein Unicode-Zeichen in CSS anwendet?
- 24. Wie man eine Funktion auf zwei Listen von Datenrahmen anwendet?
- 25. dplyr: Wie man do() auf das Ergebnis von group_by anwendet?
- 26. Wie man eine Klasse auf alle Schaltflächen anwendet?
- 27. Wie man Projektvorlage auf vorhandene Projekte in SonarQube anwendet
- 28. Wie man die Schwerkraft auf einen bestimmten Körper anwendet
- 29. Wie man itertools.product auf Elemente einer Liste von Listen anwendet?
- 30. Wie man CSS auf HTML zum Excel-Export anwendet
Ich denke, aktualisiert Sie adjwilli Antwort akzeptieren sollte, weil es einfach ant ist Ich denke, die meisten werden zustimmen, dass es der richtige Weg ist, es zu tun. – Lukas