xcode UiBarButtonItem 与“完成”按钮颜色相同

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10540566/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 00:16:51  来源:igfitidea点击:

UiBarButtonItem Same Color as "Done" Button

objective-cxcodeuibarbuttonitemuicolor

提问by Demasterpl

I want to be able to programatically add a UIBarButtonItemto a Navigation Bar and set it's tint color to the exact same blue shade as Apple's "Done" UIBarButtonItem.

我希望能够以编程方式将 a 添加UIBarButtonItem到导航栏,并将其色调设置为与 Apple 的 "Done" 完全相同的蓝色阴影UIBarButtonItem

I am already doing this for Apple's red shade in this block of code:

我已经在此代码块中为 Apple 的红色阴影执行此操作:

UIBarButtonItem *myDeleteButton = [[UIBarButtonItem alloc] initWithTitle:@"Clear" style:UIBarButtonItemStyleBordered target:self action:@selector(myDeleteItemsMethod:)];
myDeleteButton.tintcolor = [[UIColor alloc] initwithRed:1 green:0.0470275 blue:0.0116515 alpha:1];
self.navigationItem.rightBarButtonItem = myDeleteButton;

I guess all I need are the RGB values.

我想我只需要 RGB 值。

I'm having a hard time trying to "reverse engineer" a UIBarButtonItem'stint that was made in Storyboard (Can't cast UIColoras text).

我很难尝试“逆向工程”UIBarButtonItem's在 Storyboard 中制作的色调(无法转换UIColor为文本)。

And I also realize that Xcode's color palette has an area for "developer" color schemes but it does not appear to include the color for the "Done" button.

而且我还意识到 Xcode 的调色板有一个用于“开发人员”配色方案的区域,但它似乎没有包含“完成”按钮的颜色。

回答by Morgan.J.Kennedy

I spent about 15 mins with my DigitalColor Meter and basically guessed and checked until I finally got it. The problem is that you're adding a "tint" to a black button to make it blue, so it won't be the right blue. Here's the correct measurements:

我用我的 DigitalColor Meter 花了大约 15 分钟,基本上是猜测和检查,直到我最终得到它。问题是您正在向黑色按钮添加“色调”以使其变为蓝色,因此它不会是正确的蓝色。以下是正确的测量值:

[buttonName setTintColor:[UIColor colorWithRed:34.0/255.0 green:97.0/255.0 blue:221.0/255.0 alpha:1]];

Hope it helps someone :)

希望它可以帮助某人:)

回答by Jonathan Grynspan

You want UIBarButtonItemStyleDonerather than UIBarButtonItemStyleBordered.

你想要UIBarButtonItemStyleDone而不是UIBarButtonItemStyleBordered.

回答by user2014551

The proposed color of user1641653 is just the bottom color of the real DoneButton taken with the color meter. The problem is that the shadow of a plain/borderer button is different than the one of a SystemButton. The shadow will change the proposed color by -11, -36, -11. So if you really want it to look like the real DoneButton you have to add those values to the proposed 34/97/221.

user1641653 的建议颜色只是用色度计拍摄的真实 DoneButton 的底部颜色。问题是普通/边框按钮的阴影与 SystemButton 的阴影不同。阴影会将建议的颜色更改为 -11、-36、-11。因此,如果您真的希望它看起来像真正的 DoneButton,则必须将这些值添加到建议的 34/97/221。

This means:

这意味着:

[yourButton setTintColor:[UIColor colorWithRed:45.0/255.0 green:133.0/255.0 blue:232.0/255.0 alpha:1]];