【发布时间】:2010-10-26 10:26:33
【问题描述】:
您好,我想更改用户点击按钮的 UIButton 背景颜色。
我正在使用渐变显示背景颜色,当用户点击时我需要更改渐变颜色。
[btn setTitle: @"Next" forState:UIControlStateNormal];
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.frame = btn.bounds;
gradient.cornerRadius = 10.0f;
locations = [[NSArray alloc] initWithObjects: 0.0f, 0.0f, 0.0f,0.0f, nil];
[gradient setLocations:locations];
colorNext = [[NSArray alloc] initWithObjects:…., nil];
gradient.colors = colorNext;
[locations release];
[btn.layer insertSublayer:gradient atIndex:0];
btn.titleLabel.textColor = [UIColor blackColor];
【问题讨论】:
-
这个问题有很好的答案:stackoverflow.com/questions/14523348/…