|
33 | 33 |
|
34 | 34 | using CoreText; |
35 | 35 |
|
36 | | -// Disable until we get around to enable + fix any issues. |
37 | | -#nullable disable |
| 36 | +#nullable enable |
38 | 37 |
|
39 | 38 | namespace Foundation { |
40 | 39 |
|
41 | 40 | public partial class NSMutableAttributedString { |
42 | 41 |
|
43 | | - /// <param name="str">C# string.</param> |
44 | | - /// <param name="attributes">CoreText attributes to be applied to the string.</param> |
45 | | - /// <summary>Creates an NSMutableAttributedString from a C# string and applies the specified CoreText attributes to the entire string.</summary> |
46 | | - /// <remarks> |
47 | | - /// </remarks> |
48 | | - public NSMutableAttributedString (string str, CTStringAttributes attributes) |
49 | | - : this (str, attributes is null ? null : attributes.Dictionary) |
| 42 | + /// <summary> |
| 43 | + /// Creates an NSMutableAttributedString from a C# string and applies the specified CoreText attributes to the entire string. |
| 44 | + /// </summary> |
| 45 | + /// <param name="str">The string content.</param> |
| 46 | + /// <param name="attributes">CoreText attributes to be applied to the string.</param> |
| 47 | + public NSMutableAttributedString (string str, CTStringAttributes? attributes) |
| 48 | + : this (str, attributes?.Dictionary) |
50 | 49 | { |
51 | 50 | } |
52 | 51 |
|
53 | | - /// <param name="attributes">To be added.</param> |
54 | | - /// <param name="range">Range to which the attribute will be applied.</param> |
55 | | - /// <summary>Sets the attributes for the specified ranges. Any previous attributes in that range are replaces with the new values.</summary> |
56 | | - /// <remarks> |
57 | | - /// </remarks> |
| 52 | + /// <summary> |
| 53 | + /// Sets the attributes for the specified range. Any previous attributes in that range are replaced with the new values. |
| 54 | + /// </summary> |
| 55 | + /// <param name="attributes">The attributes to set.</param> |
| 56 | + /// <param name="range">The range to which the attributes will be applied.</param> |
58 | 57 | public void SetAttributes (NSDictionary attributes, NSRange range) |
59 | 58 | { |
60 | | - if (attributes is null) |
61 | | - throw new ArgumentNullException ("attributes"); |
| 59 | + ArgumentNullException.ThrowIfNull (attributes); |
62 | 60 |
|
63 | 61 | LowLevelSetAttributes (attributes.Handle, range); |
64 | 62 | GC.KeepAlive (attributes); |
65 | 63 | } |
66 | 64 |
|
| 65 | + /// <summary> |
| 66 | + /// Sets the attributes for the specified range. Any previous attributes in that range are replaced with the new values. |
| 67 | + /// </summary> |
67 | 68 | /// <param name="attrs">CoreText attributes to be set on the string.</param> |
68 | | - /// <param name="range">Range to which the attribute will be applied.</param> |
69 | | - /// <summary>Sets the attributes for the specified ranges. Any previous attributes in that range are replaces with the new values.</summary> |
70 | | - /// <remarks> |
71 | | - /// </remarks> |
| 69 | + /// <param name="range">The range to which the attributes will be applied.</param> |
72 | 70 | public void SetAttributes (CTStringAttributes attrs, NSRange range) |
73 | 71 | { |
74 | | - SetAttributes (attrs is null ? null : attrs.Dictionary, range); |
| 72 | + ArgumentNullException.ThrowIfNull (attrs); |
| 73 | + |
| 74 | + SetAttributes (attrs.Dictionary, range); |
75 | 75 | } |
76 | 76 |
|
| 77 | + /// <summary> |
| 78 | + /// Adds attributes to the specified range of characters in the string. |
| 79 | + /// </summary> |
77 | 80 | /// <param name="attrs">The CoreText attributes to add.</param> |
78 | | - /// <param name="range">Range to which the attribute will be applied.</param> |
79 | | - /// <summary>Adds an attribute and its value to the specified range of characters in the string.</summary> |
80 | | - /// <remarks> |
81 | | - /// </remarks> |
| 81 | + /// <param name="range">The range to which the attributes will be applied.</param> |
82 | 82 | public void AddAttributes (CTStringAttributes attrs, NSRange range) |
83 | 83 | { |
84 | | - AddAttributes (attrs is null ? null : attrs.Dictionary, range); |
| 84 | + ArgumentNullException.ThrowIfNull (attrs); |
| 85 | + |
| 86 | + AddAttributes (attrs.Dictionary, range); |
85 | 87 | } |
86 | 88 |
|
87 | | - /// <param name="first">To be added.</param> |
88 | | - /// <param name="rest">To be added.</param> |
89 | | - /// <summary>To be added.</summary> |
90 | | - /// <remarks>To be added.</remarks> |
| 89 | + /// <summary> |
| 90 | + /// Appends an attributed string and additional objects to the end of the receiver. |
| 91 | + /// </summary> |
| 92 | + /// <param name="first">The first attributed string to append.</param> |
| 93 | + /// <param name="rest">Additional objects to append. Can be <see cref="NSAttributedString"/>, <see cref="string"/>, or other objects whose <see cref="object.ToString"/> method will be called.</param> |
91 | 94 | public void Append (NSAttributedString first, params object [] rest) |
92 | 95 | { |
93 | 96 | Append (first); |
94 | 97 | foreach (var obj in rest) { |
95 | | - if (obj is NSAttributedString) |
96 | | - Append ((NSAttributedString) obj); |
97 | | - else if (obj is string) |
98 | | - Append (new NSAttributedString ((string) obj)); |
| 98 | + if (obj is NSAttributedString nsAttributedString) |
| 99 | + Append (nsAttributedString); |
| 100 | + else if (obj is string str) |
| 101 | + Append (new NSAttributedString (str)); |
99 | 102 | else |
100 | | - Append (new NSAttributedString (obj.ToString ())); |
| 103 | + Append (new NSAttributedString (obj.ToString () ?? "")); |
101 | 104 |
|
102 | 105 | } |
103 | 106 | } |
104 | 107 | #if !MONOMAC |
105 | | - /// <param name="str">To be added.</param> |
106 | | - /// <param name="attributes">To be added.</param> |
107 | | - /// <summary>To be added.</summary> |
108 | | - /// <remarks>To be added.</remarks> |
109 | | - public NSMutableAttributedString (string str, UIStringAttributes attributes) |
110 | | - : this (str, attributes is not null ? attributes.Dictionary : null) |
| 108 | + /// <summary> |
| 109 | + /// Creates an NSMutableAttributedString from a string with UIKit attributes. |
| 110 | + /// </summary> |
| 111 | + /// <param name="str">The string content.</param> |
| 112 | + /// <param name="attributes">UIKit attributes to be applied to the string.</param> |
| 113 | + public NSMutableAttributedString (string str, UIStringAttributes? attributes) |
| 114 | + : this (str, attributes?.Dictionary) |
111 | 115 | { |
112 | 116 | } |
113 | 117 |
|
114 | | - /// <param name="str">To be added.</param> |
115 | | - /// <param name="font">To be added.</param> |
116 | | - /// <param name="foregroundColor">To be added.</param> |
117 | | - /// <param name="backgroundColor">To be added.</param> |
118 | | - /// <param name="strokeColor">To be added.</param> |
119 | | - /// <param name="paragraphStyle">To be added.</param> |
120 | | - /// <param name="ligatures">To be added.</param> |
121 | | - /// <param name="kerning">To be added.</param> |
122 | | - /// <param name="underlineStyle">To be added.</param> |
123 | | - /// <param name="shadow">To be added.</param> |
124 | | - /// <param name="strokeWidth">To be added.</param> |
125 | | - /// <param name="strikethroughStyle">To be added.</param> |
126 | | - /// <summary>To be added.</summary> |
127 | | - /// <remarks>To be added.</remarks> |
| 118 | + /// <summary> |
| 119 | + /// Creates an NSMutableAttributedString from a string with individual UIKit styling attributes. |
| 120 | + /// </summary> |
| 121 | + /// <param name="str">The string content.</param> |
| 122 | + /// <param name="font">The font to apply to the string.</param> |
| 123 | + /// <param name="foregroundColor">The foreground (text) color.</param> |
| 124 | + /// <param name="backgroundColor">The background color.</param> |
| 125 | + /// <param name="strokeColor">The stroke color for outlined text.</param> |
| 126 | + /// <param name="paragraphStyle">The paragraph style to apply.</param> |
| 127 | + /// <param name="ligatures">The ligature type to use.</param> |
| 128 | + /// <param name="kerning">The kerning value to apply.</param> |
| 129 | + /// <param name="underlineStyle">The underline style to apply.</param> |
| 130 | + /// <param name="shadow">The shadow effect to apply.</param> |
| 131 | + /// <param name="strokeWidth">The stroke width for outlined text.</param> |
| 132 | + /// <param name="strikethroughStyle">The strikethrough style to apply.</param> |
128 | 133 | public NSMutableAttributedString (string str, |
129 | | - UIFont font = null, |
130 | | - UIColor foregroundColor = null, |
131 | | - UIColor backgroundColor = null, |
132 | | - UIColor strokeColor = null, |
133 | | - NSParagraphStyle paragraphStyle = null, |
| 134 | + UIFont? font = null, |
| 135 | + UIColor? foregroundColor = null, |
| 136 | + UIColor? backgroundColor = null, |
| 137 | + UIColor? strokeColor = null, |
| 138 | + NSParagraphStyle? paragraphStyle = null, |
134 | 139 | NSLigatureType ligatures = NSLigatureType.Default, |
135 | 140 | float kerning = 0, |
136 | 141 | NSUnderlineStyle underlineStyle = NSUnderlineStyle.None, |
137 | | - NSShadow shadow = null, |
| 142 | + NSShadow? shadow = null, |
138 | 143 | float strokeWidth = 0, |
139 | 144 | NSUnderlineStyle strikethroughStyle = NSUnderlineStyle.None) |
140 | 145 | : this (str, ToDictionary (font, foregroundColor, backgroundColor, strokeColor, paragraphStyle, ligatures, kerning, underlineStyle, shadow, strokeWidth, strikethroughStyle)) |
|
0 commit comments