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

how to change the system image color of the button with objctive-c

作为新手,想请教如何用代码的方式改变按钮的系统图片颜色。我曾经在故事板中操作。我尝试使用 btn Tintcolor 和 btn imageView。 Tintcolor要修改,还有titlecolor,但是不行

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

// 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]];

结果: