所以我的playCardLabel的文字是@“ A \ u2663 ”
- (IBAction)flipCardButtonTapped:(UIButton *)sender
{
if([self.playingCardLabel.textColor isEqual:[UIColor whiteColor]])
self.playingCardLabel.textColor = [UIColor blackColor];
else
self.playingCardLabel.textColor = [UIColor whiteColor];
}
当我点击按钮时,只有A变为白色,铲子(或其他任何东西)无论如何都保持黑色?
答案 0 :(得分:2)
这些符号看起来是固定的颜色。使用\U2663
表示黑人俱乐部(♣♣),并使用\U2667
表示白人俱乐部(♧)。有类似的黑色或白色版本的铁锹,心脏和钻石。
答案 1 :(得分:0)
使用您的颜色从unicode符号创建图像。使用UIImageView代替UILabel,或者使用UILabel和NSAttributedString + NSTextAttachment(图片里面)。
@implementation NSString (OSExt)
- (UIImage *)toImageWithAttributes:(NSDictionary*)attributes
{
CGSize size = [self sizeWithAttributes:attributes];
UIGraphicsBeginImageContextWithOptions(size, NO, 0.0);
[self drawAtPoint:CGPointZero withAttributes:attributes];
CGContextRef imgctx = UIGraphicsGetCurrentContext();
// use blend mode to fill symbols like @"♣︎"
CGContextSetBlendMode(imgctx, kCGBlendModeSourceAtop);
CGContextSetFillColorWithColor(imgctx, [attributes[NSForegroundColorAttributeName] CGColor]);
CGContextFillRect(imgctx, (CGRect){CGPointZero, size});
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return image;
}
@end
// use
id attrs = @{NSForegroundColorAttributeName:[UIColor greenColor]};
UIImage *image = [@"♣︎" toImageWithAttributes:attrs];