【问题标题】:How to get the original color of the image如何获得图像的原始颜色
【发布时间】:2019-06-19 17:07:18
【问题描述】:

我尝试在 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);
}

【问题讨论】:

    标签: ios objective-c tweak


    【解决方案1】:

    改变

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

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

    【讨论】:

      猜你喜欢
      • 2014-11-21
      • 2016-09-15
      • 2012-09-06
      • 2015-05-11
      • 1970-01-01
      • 1970-01-01
      • 2015-09-12
      • 2011-02-02
      • 1970-01-01
      相关资源
      最近更新 更多