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
CodePudding user response:
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: