gpt4 book ai didi

iphone - 如何给 UIButton 着色?

转载 作者:行者123 更新时间:2023-12-03 18:38:03 25 4
gpt4 key购买 nike

我正在向我的 iPhone UI 添加自定义按钮,并希望使它们具有 Apple 应用程序中的玻璃外观。我有一个很好的默认玻璃图像,但我不想为我想要的每种色调(红色、绿色、蓝色等)都有一个单独的图像。

有没有办法加载灰度PNG并将其调整为我想要的颜色?更好的是,有没有一种方法无需加载自定义图像即可获得 Apple 的玻璃外观?

最佳答案

有点晚了,但万一像我这样的人搜索此类信息:使用带有单个按钮的 UISegmentedControl,将其设置为 momentary,然后设置其tintColor。这样,无需准备与颜色一样多的 PNG,并且框架会为您处理所有渲染。

示例:

UISegmentedControl *cancelButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"Cancel"]];
[cancelButton setSegmentedControlStyle:UISegmentedControlStyleBar];
[cancelButton setTintColor:[UIColor colorWithRed:0.8 green:0.3 blue:0.3 alpha:1.0]];
[cancelButton setMomentary:YES];
[cancelButton addTarget:self action:@selector(didTapCancel:) forControlEvents:UIControlEventValueChanged];
[self addSubview:cancelButton];
[cancelButton release];

关于iphone - 如何给 UIButton 着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/121615/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com