如何获得图像的原始颜色

时间:2019-06-19 17:07:18

标签: ios objective-c tweak

我尝试在rebootButton按钮上获取图像的原始颜色 我可以更改颜色..但我想获得在Photoshop中创建的图像的原始颜色

问题是我无法获得原始颜色,而整个图片仅得到蓝色 我可以帮忙吗?

 UIColor* tintColor;

UIButton *rebootButton = [[UIButton buttonWithType:UIButtonTypeRoundedRect] retain];
rebootButton.frame = CGRectMake(self.view.frame.size.width - 250, self.view.frame.size.height / 2 - 80, 60, 60);
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
[rebootButton setTitle:@"Reboot" forState:UIControlStateNormal];
[rebootButton addTarget:self action:@selector(reboot) forControlEvents:UIControlEventTouchUpInside];

if(style != 1) {
rebootButton.tintColor = tintColor;
} else {
if(defaultTheme1 == 0) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot1] forState:UIControlStateNormal];
} else if (defaultTheme1 == 1) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot2] forState:UIControlStateNormal];
} else if (defaultTheme1 == 2) {
[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];
}
}
[powerButton centerVertically];
[myView addSubview:powerButton];

// Load preferences using HBPreferences, I could use NSUserDefaults but HBPreferences is fine for now.
static void loadPrefs() {
NSString *kBackgroundColor = @"";
NSString *kTintColor = @"";

[colorPrefs registerDefaults:@{
@"kBackgroundColor": @"#FFFFFF",
@"kTintColor": @"#007AFF"
}];


kTintColor = [colorPrefs objectForKey:@"kTintColor"];
// Set the tint and background colour to a UIColor
tintColor = LCPParseColorString(kTintColor, kTintColor);
backgroundColor = LCPParseColorString(kBackgroundColor, kBackgroundColor);
}

1 个答案:

答案 0 :(得分:0)

更改

[rebootButton setImage:[UIImage imageWithContentsOfFile: reboot3] forState:UIControlStateNormal];

收件人

[rebootButton setImage:[[UIImage imageWithContentsOfFile: reboot3] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];