더 이상 사용되지 않는 API를 사용하지 않고 그림자로 그릴 다중 선 텍스트를 얻으려고합니다. 그것은 한 줄에 잘 작동합니다.다중 선 nsstring에서 그림자를 얻을 수 없습니다.
-(void)drawRect:(CGRect)rect
{
NSMutableParagraphStyle *paragraph = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraph.lineBreakMode = NSLineBreakByWordWrapping;
paragraph.alignment = NSTextAlignmentCenter;
UIFont *f = [UIFont systemFontOfSize:20.0];
NSMutableDictionary *attributes = [NSMutableDictionary new];
[attributes setValuesForKeysWithDictionary:@{ NSFontAttributeName : f,
NSParagraphStyleAttributeName : paragraph,
NSForegroundColorAttributeName : [UIColor blueColor] }];
NSShadow * shadow = [NSShadow new];
shadow.shadowOffset = CGSizeMake(4,4);
shadow.shadowColor = [UIColor redColor];
[attributes setValue:shadow forKey:NSShadowAttributeName];
rect.origin.y = 100;
[@"test string on one line" drawInRect:rect withAttributes:attributes];
rect.origin.y = 150;
[@"test string spanning more than one line" drawInRect:rect withAttributes:attributes];
}
을 출력은 다음과 같습니다 : 관련 코드는 다음과 같습니다 나는 아이폰 5 (7.1.2), 아이폰 6 (8.0), 건물에 검사를하지
또한 xCode 5로 빌드 할 때 iPhone 5에서 테스트했습니다.
지옥, 나는 두 개의 동일한 라벨을 사용했을 것입니다. 하나는 다른 하나를 오버레이하고 오프셋은 투명 배경입니다. –
그건 0이 아닌 shadowBlurRadius에서 작동하지 않을까요? –