首页 文章

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

提问于
浏览
4

我希望能够以编程方式将 UIBarButtonItem 添加到导航栏并将其设置为's tint color to the exact same blue shade as Apple' s "Done" UIBarButtonItem .

我已经在这段代码中为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;

我想我需要的只是RGB值 .

我很难在故事板中尝试"reverse engineer" UIBarButtonItem's 色调(不能将 UIColor 转换为文本) .

我也意识到Xcode的调色板有一个“开发人员”颜色方案的区域,但它似乎没有包含“完成”按钮的颜色 .

3 回答

  • 14

    我用我的DigitalColor仪表花了大约15分钟,基本上猜到并检查,直到我终于得到它 . 问题是你在黑色按钮上添加了“色调”使其变蓝,因此它不会是正确的蓝色 . 这是正确的测量:

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

    希望它可以帮助别人:)

  • 5

    你想 UIBarButtonItemStyleDone 而不是 UIBarButtonItemStyleBordered .

  • 8

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

    这意味着:

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

相关问题