è possibile applicare sia ictus e riempire con una NSAttributedString
e UILabel
?Come posso sia ictus e riempire con NSAttributedString w/UILabel
33
A
risposta
71
Sì, la chiave è quello di applicare un valore negativo al NSStrokeWidthAttributeName
Se questo valore è positivo si vedrà solo la corsa e non il riempimento.
Objective-C:
self.label.attributedText=[[NSAttributedString alloc]
initWithString:@"string to both stroke and fill"
attributes:@{
NSStrokeWidthAttributeName: @-3.0,
NSStrokeColorAttributeName:[UIColor yellowColor],
NSForegroundColorAttributeName:[UIColor redColor]
}
];
Grazie alla @cacau di seguito: Vedi anche Technical Q&A QA1531
versione Swift:
let attributes = [NSStrokeWidthAttributeName: -3.0,
NSStrokeColorAttributeName: UIColor.yellowColor(),
NSForegroundColorAttributeName: UIColor.redColor()];
label.attributedText = NSAttributedString(string: "string to both stroke and fill", attributes: attributes)
Swift 3 versione:
let attributes = [NSStrokeWidthAttributeName: -3.0,
NSStrokeColorAttributeName: UIColor.yellow,
NSForegroundColorAttributeName: UIColor.red] as [String : Any]
label.attributedText = NSAttributedString(string: "string to both stroke and fill", attributes: attributes)
7
Swift versione:
let attributes = [NSStrokeWidthAttributeName: -3.0,
NSStrokeColorAttributeName: UIColor.yellowColor(),
NSForegroundColorAttributeName: UIColor.redColor()];
label.attributedText = NSAttributedString(string: "string to both stroke and fill", attributes: attributes)
Swift 3 versione:
let attributes = [NSStrokeWidthAttributeName: -3.0,
NSStrokeColorAttributeName: UIColor.yellow,
NSForegroundColorAttributeName: UIColor.red] as [String : Any]
label.attributedText = NSAttributedString(string: "string to both stroke and fill", attributes: attributes)
0
Ora Ultimo nella mela rapida rimuovere il [String: Qualsiasi] per la chiave attributi uso dichiarazione di valore come [NSAttributedStringKey: Qualsiasi]
let strokeTextAttributes = [
NSAttributedStringKey.strokeColor : UIColor.green,
NSAttributedStringKey.foregroundColor : UIColor.lightGray,
NSAttributedStringKey.strokeWidth : -4.0,
NSAttributedStringKey.font : UIFont.boldSystemFont(ofSize: 52)
] as [NSAttributedStringKey : Any]
hello_cell_lb.attributedText = NSAttributedString(string: "\(hello_array[indexPath.row])", attributes: strokeTextAttributes)
grazie
Problemi correlati
- 1. NSTextView e NSAttributedString
- 2. svg clip di immagine e spettacolo ictus
- 3. Come impostareHighlightedTextColor @ NSAttributedString
- 4. Come creare pedici e apici usando NSAttributedString?
- 5. Come posso riempire un div con un'immagine mantenendolo proporzionale?
- 6. come riempire un'immagine con motivo
- 7. Come posso visualizzare una NSAttributedString su un iPhone?
- 8. Come posso riempire RecyclerView con GridLayoutManager da destra a sinistra
- 9. Visualizza NSAttributedString utilizzando CoreText
- 10. Come posso riempire una griglia matplotlib?
- 11. Come posso riempire gli array in Java?
- 12. Davvero le linee vicine con NSAttributedString?
- 13. Copia NSAttributedString in UIPasteBoard
- 14. iOS NSAttributedString su UIButton
- 15. Come riempire l'editor di tinymce-rails con capibara e selenio?
- 16. Come ritagliare e riempire con Paperclip (o RMagick)?
- 17. Come posso sfruttare sia State sia Writer in haskell?
- 18. Come riempire rettangolo con l'opacità in Android
- 19. Latex to NSAttributedString?
- 20. Posso utilizzare NSAttributedString in Core Text in iOS?
- 21. Come riempire una matrice con zero (0)
- 22. Come animare arco/ciambella segmento ictus e il cambiamento di lunghezza
- 23. Come disegnare e riempire un triangolo con QPainter?
- 24. Come riempire NA con la mediana?
- 25. Come riempire DataTable con la tabella SQL
- 26. Come riempire l'area del grafico con Colore
- 27. Come riempire Spinner con valore int
- 28. Come riempire Matrix con zeri in OpenCV?
- 29. Riempire DataGrid con righe vuote
- 30. NSAttributedString troncamento coda in UILabel
Si noti che il "contorno" sarà un contorno interno, non esterno, cioè il contorno si mangerà nell'area di riempimento. – Jason
@Jason c'è un modo per generare un riempimento "esterno" con UILabel + AttributesedText? –
Non ho scoperto come ... – Jason