蓝色矩形中的 UIStepper 自定义结果
UIStepper Customization Results in Blue Rectangles
我一直在尝试自定义通过 Interface Builder 添加的 UIStepper 对象的外观。在参考主题 here 和其他主题时,我向 viewDidLoad 添加了几行代码。
- (void)viewDidLoad {
[[UIStepper appearance] setIncrementImage:[UIImage imageNamed:@"stepperupImage.tif"] forState:UIControlStateNormal];
[[UIStepper appearance] setDecrementImage:[UIImage imageNamed:@"stepperdownImage.tif"] forState:UIControlStateNormal];
}
结果是死亡的蓝色矩形,如下所示。 UIStepper 没有像 UIButtonTypeCustom 这样的 属性。有人知道如何解决这个问题吗?我的部署目标是 iOS 8.0.
谢谢。
要渲染没有原始透明度的图像,可以:
- 将“渲染为”设置更改为“原始图像”(仅限 .xcasset 文件):
— 或 —
在代码中更改渲染模式(docs):
UIImage *image;
image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
在您的情况下,代码如下所示:
[[UIStepper appearance] setIncrementImage:[[UIImage imageNamed:@"stepperupImage.tif"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[[UIStepper appearance] setDecrementImage:[[UIImage imageNamed:@"stepperdownImage.tif"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
UIImage *incrementImageFromFile = [UIImage imageNamed:@"plus.png"];
UIImage *incrementImage = [incrementImageFromFile imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *decrementImageFromFile = [UIImage imageNamed:@"minus.png"];
UIImage *decrementImage = [decrementImageFromFile imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// For Normal state
[stepper setIncrementImage:incrementImage forState:UIControlStateNormal];
[stepper setDecrementImage:decrementImage forState:UIControlStateNormal];
// For Highlighted state
[stepper setIncrementImage:incrementImage forState:UIControlStateHighlighted];
[stepper setDecrementImage:decrementImage forState:UIControlStateHighlighted];
我一直在尝试自定义通过 Interface Builder 添加的 UIStepper 对象的外观。在参考主题 here 和其他主题时,我向 viewDidLoad 添加了几行代码。
- (void)viewDidLoad {
[[UIStepper appearance] setIncrementImage:[UIImage imageNamed:@"stepperupImage.tif"] forState:UIControlStateNormal];
[[UIStepper appearance] setDecrementImage:[UIImage imageNamed:@"stepperdownImage.tif"] forState:UIControlStateNormal];
}
结果是死亡的蓝色矩形,如下所示。 UIStepper 没有像 UIButtonTypeCustom 这样的 属性。有人知道如何解决这个问题吗?我的部署目标是 iOS 8.0.
谢谢。
要渲染没有原始透明度的图像,可以:
- 将“渲染为”设置更改为“原始图像”(仅限 .xcasset 文件):
— 或 —
在代码中更改渲染模式(docs):
UIImage *image; image = [image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
在您的情况下,代码如下所示:
[[UIStepper appearance] setIncrementImage:[[UIImage imageNamed:@"stepperupImage.tif"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
[[UIStepper appearance] setDecrementImage:[[UIImage imageNamed:@"stepperdownImage.tif"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
UIImage *incrementImageFromFile = [UIImage imageNamed:@"plus.png"];
UIImage *incrementImage = [incrementImageFromFile imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
UIImage *decrementImageFromFile = [UIImage imageNamed:@"minus.png"];
UIImage *decrementImage = [decrementImageFromFile imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
// For Normal state
[stepper setIncrementImage:incrementImage forState:UIControlStateNormal];
[stepper setDecrementImage:decrementImage forState:UIControlStateNormal];
// For Highlighted state
[stepper setIncrementImage:incrementImage forState:UIControlStateHighlighted];
[stepper setDecrementImage:decrementImage forState:UIControlStateHighlighted];