페이지

2017년 3월 30일 목요일

iOS UILabel attributedText NSForegroundColorAttributeName property doesn't work. its forecolor is transparent.






@interface UIStrokeLabel : UILabel
@property (nonatomic, assign) CGFloat stokeWidth;
@end



@implementation UIStrokeLabel
- (void)drawTextInRect:(CGRect)rect{
    self.attributedText = [[NSAttributedString alloc]
                           initWithString:self.text
                           attributes:@{
                                        NSStrokeWidthAttributeName: [NSNumber numberWithFloat:self.strokeWidth],
                                        NSStrokeColorAttributeName:[UIColor blueColor],
                                        NSForegroundColorAttributeName:self.textColor
                                        }
                           ];
    
    [super drawTextInRect:rect];
}
@end

self.strokeWidth must be under 0. 
if it is over 0, text fore color is transparent.

댓글 없음:

댓글 쓰기