我创建了一个自定义按钮,因为我想要一个渐变按钮.所以我用这段代码来实现它. @H_419_12@@implementation Custombutton- (ID)initWithFrame:(CGRect)frame{ if((self = [super initWithFrame:frame])){ [self setupVIEw]; } //[self addobserver:self forKeyPath:@"highlighted" options:0 context:nil]; return self;}- (voID)awakeFromNib { [self setupVIEw];}# pragma mark - main- (voID)setupVIEw{ self.layer.cornerRadius = 10; self.layer.borderWIDth = 1.0; self.layer.bordercolor = [UIcolor colorWithRed:167.0/255.0 green:140.0/255.0 blue:98.0/255.0 Alpha:0.25].CGcolor; self.layer.shadowcolor = [UIcolor blackcolor].CGcolor; self.layer.shadowRadius = 1; [self clearHighlightVIEw]; CAGradIEntLayer *gradIEnt = [CAGradIEntLayer layer]; gradIEnt.frame = self.layer.bounds; gradIEnt.cornerRadius = 10; gradIEnt.colors = [NSArray arrayWithObjects: (ID)[UIcolor colorWithWhite:1.0f Alpha:0.4f].CGcolor,(ID)[UIcolor colorWithWhite:1.0f Alpha:0.2f].CGcolor,(ID)[UIcolor colorWithWhite:0.75f Alpha:0.2f].CGcolor,(ID)[UIcolor colorWithWhite:0.4f Alpha:0.2f].CGcolor,(ID)[UIcolor colorWithWhite:1.0f Alpha:0.4f].CGcolor,nil]; // float height = gradIEnt.frame.size.height; gradIEnt.locations = [NSArray arrayWithObjects: [NSNumber numberWithfloat:0.0f],[NSNumber numberWithfloat:0.5f],[NSNumber numberWithfloat:0.8f],[NSNumber numberWithfloat:1.0f],nil]; [gradIEnt setBackgroundcolor:[UIcolor redcolor].CGcolor]; [self.layer insertSublayer:gradIEnt atIndex:0];}
现在渐变已经完成.但是当我按下此按钮时,它上面没有突出显示的状态.
我只是想按下它的颜色已加深.
有谁知道如何实现这个?谢谢
以上是内存溢出为你收集整理的ios – 如何制作突出显示的[自定义按钮]全部内容,希望文章能够帮你解决ios – 如何制作突出显示的[自定义按钮]所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)