【问题标题】:how to set UILabel text colour as a a background image如何将 UILabel 文本颜色设置为背景图像
【发布时间】:2014-04-02 19:43:38
【问题描述】:

我想设计一个视图,其中UILabel 文本应保持透明,以便背景图像可以通过文本看到,即UILabel 的透明文本 随着移动UILabel,文字颜色应根据背景变化 图片 请帮帮我

UIImage *croppedImage=[self crop:self.demo.frame];

 self.demo.textColor=[UIColor colorWithPatternImage:croppedImage];

我正在裁剪演示大小的图像(UILabel)并设置其文本颜色 但图像得到双重像素化

【问题讨论】:

  • [self crop:self.demo.frame] 检查这个方法,你没有得到正确的裁剪
  • 你能建议我吗,如何用 UILabel 大小裁剪背景 imageView 图像?
  • 您应该分析哪种类型的 textcolor 与图像颜色匹配,例如,如果您有黑色图像,请尝试使用 uilabel 的 darktextcolor

标签: ios


【解决方案1】:

通过传递准确的 LabelSize 来裁剪图像;

// get sub image
- (UIImage*) getSubImageFrom: (UIImage*) img WithRect: (CGRect) rect {

    UIGraphicsBeginImageContext(rect.size);
    CGContextRef context = UIGraphicsGetCurrentContext();

    // translated rectangle for drawing sub image
    CGRect drawRect = CGRectMake(-rect.origin.x, -rect.origin.y, img.size.width, img.size.height);

    // clip to the bounds of the image context
    // not strictly necessary as it will get clipped anyway?
    CGContextClipToRect(context, CGRectMake(0, 0, rect.size.width, rect.size.height));

    // draw image
    [img drawInRect:drawRect];

    // grab image
    UIImage* subImage = UIGraphicsGetImageFromCurrentImageContext();

    UIGraphicsEndImageContext();

    return subImage;
}

【讨论】:

  • 亲爱的它的工作,但图像得到双像素化,即图像得到双倍
  • 怎么来的。然后检查您的图像。它应该是同一框架。将 imgView.ContentMode 设置为 aspectFit
  • 是否有任何视网膜或非视网膜问题@Kumar KI
  • 是的,这可能会导致。你是如何处理图像的
  • 我有两个视图方形和矩形视图。并裁剪通过任何一个视图看到的图像。并设置为 finaleImageView 以适应宽高比。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-28
  • 1970-01-01
  • 1970-01-01
  • 2011-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多