Skip to content

Commit 7f362ee

Browse files
committed
Move text attributes to local var for DRY concerns
1 parent ed6e020 commit 7f362ee

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

UIImageView+Letters/UIImageView+Letters.m

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,18 @@ - (UIImage *)imageSnapshotFromText:(NSString *)text backgroundColor:(UIColor *)c
155155
//
156156
// Draw text in the context
157157
//
158-
CGSize textSize = [text sizeWithAttributes:@{NSFontAttributeName:[self fontForText:fontName]}];
158+
NSDictionary *textAttributes = @{
159+
NSFontAttributeName:[self fontForText:fontName],
160+
NSForegroundColorAttributeName:[UIColor whiteColor]
161+
};
162+
CGSize textSize = [text sizeWithAttributes:textAttributes];
159163
CGRect bounds = self.bounds;
160164

161165
[text drawInRect:CGRectMake(bounds.size.width/2 - textSize.width/2,
162166
bounds.size.height/2 - textSize.height/2,
163167
textSize.width,
164168
textSize.height)
165-
withAttributes:@{
166-
NSFontAttributeName:[self fontForText:fontName],
167-
NSForegroundColorAttributeName:[UIColor whiteColor]
168-
}];
169+
withAttributes:textAttributes];
169170

170171
UIImage *snapshot = UIGraphicsGetImageFromCurrentImageContext();
171172
UIGraphicsEndImageContext();

0 commit comments

Comments
 (0)