如何使用objctive-c更改按钮的系统图像颜色

发布于 2025-02-04 03:13:18 字数 107 浏览 1 评论 0原文

作为新手,我想询问如何以代码方式更改按钮的系统图像颜色。我曾经在故事板上操作。我尝试使用BTN Tintcolor和BTN ImageView。 tintcolor修改和titlecolor,但行不通

As a novice, I want to ask how to change the system image color of the button in the way of code. I used to operate in storyboard. I tried to use btn Tintcolor and btn imageView. Tintcolor to modify, and titlecolor, but it doesn't work

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

挽清梦 2025-02-11 03:13:18

这是一个非常基本的示例:

// create a button
UIButton *b = [UIButton new];

// set its title
[b setTitle:@"My Title" forState:UIControlStateNormal];

// set the "normal" title color to White
[b setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

// set the "highlighted" title color to Light Gray
[b setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];

// set the background color to Blue
[b setBackgroundColor:[UIColor blueColor]];

// get a system image with Template Rendering
UIImage *img = [[UIImage systemImageNamed:@"person.circle.fill"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

// set the button's image
[b setImage:img forState:UIControlStateNormal];

// set the image tint color to Red
[b setTintColor:[UIColor redColor]];

结果:

”在此处输入图像描述

This is a very basic example:

// create a button
UIButton *b = [UIButton new];

// set its title
[b setTitle:@"My Title" forState:UIControlStateNormal];

// set the "normal" title color to White
[b setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

// set the "highlighted" title color to Light Gray
[b setTitleColor:[UIColor lightGrayColor] forState:UIControlStateHighlighted];

// set the background color to Blue
[b setBackgroundColor:[UIColor blueColor]];

// get a system image with Template Rendering
UIImage *img = [[UIImage systemImageNamed:@"person.circle.fill"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

// set the button's image
[b setImage:img forState:UIControlStateNormal];

// set the image tint color to Red
[b setTintColor:[UIColor redColor]];

Result:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文