0

所以我有一个 1px 宽度和 50px 高度的 .png 文件,我想在 UISegmentedButton 中水平平铺它,所以我做了:

[segmentedCtrl setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"btn-gradient-brown.png"]]];

然而,我得到的只是黑色。这是为什么以及如何正确执行此操作?这是我拥有的 1px,如果它有助于澄清我的观点

在此处输入图像描述

4

1 回答 1

0

您可以尝试使用核心图形方法进行平铺,从this question看这段代码,

CGSize imageViewSize = imageView.bounds.size;
UIGraphicsBeginImageContext(imageViewSize);
CGContextRef imageContext = UIGraphicsGetCurrentContext();
CGContextDrawTiledImage(imageContext, (CGRect){ CGPointZero, imageViewSize }, tileImage);
UIImage *finishedImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

它创建一个带标题的图像。您可以将图像设置为 UIcontrol 的背景。

编辑: tintColor是创建分段控制默认渐变的基础。因此,将棕色渐变图像设置为色调颜色会为您提供黑色渐变。要设置渐变颜色,

  • uisegmentcontrol类和覆盖drawRect方法。
  • 使用backgroundImage并设置适当的图像插图。
于 2012-05-24T05:00:05.383 回答