作為一個新手,想請教一下如何通過代碼的方式來改變按鈕的系統影像顏色。我曾經在故事板中操作。我嘗試使用 btn Tintcolor 和 btn imageView。Tintcolor要修改,還有titlecolor,但是不行
uj5u.com熱心網友回復:
這是一個非常基本的例子:
// 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]];
結果:

轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/490030.html
