ios – 如何使用渐变和突出显示创建UIButton?

ios – 如何使用渐变和突出显示创建UIButton?,第1张

概述我正在尝试创建一个渐变背景的UIButton.我选择时工作正常,但按钮不突出显示(默认行为是按钮变暗). 这是我的按钮: -(UIButton *)createLoginButtonForSize:(CGSize)size { UIButton *loginButton = [UIButton buttonWithType:UIButtonTypeCustom]; loginBut @H_403_2@ 我正在尝试创建一个渐变背景的UIbutton.我选择时工作正常,但按钮不突出显示(默认行为是按钮变暗).

这是我的按钮:

-(UIbutton *)createLoginbuttonForSize:(CGSize)size {    UIbutton *loginbutton = [UIbutton buttonWithType:UIbuttonTypeCustom];    loginbutton.translatesautoresizingMaskIntoConstraints = FALSE;    loginbutton.layer.cornerRadius = 8;    loginbutton.TitleLabel.text = @"Login";    [loginbutton addTarget:self action:@selector(loginCheck:) forControlEvents:UIControlEventtouchUpInsIDe];    [loginbutton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[loginbutton(WIDTH)]"                                                                        options:0                                                                        metrics:@{@"WIDTH": [NSNumber numberWithfloat:size.wIDth]}                                                                          vIEws:NSDictionaryOfVariableBindings(loginbutton)]];    [loginbutton addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:[loginbutton(HEIGHT)]"                                                                        options:0                                                                        metrics:@{@"HEIGHT": [NSNumber numberWithfloat:size.height]}                                                                          vIEws:NSDictionaryOfVariableBindings(loginbutton)]];    CAGradIEntLayer *layer = [UIcolor greenGradIEnt];    layer.frame = CGRectMake(0,size.wIDth,size.height);    layer.cornerRadius = 8;    [loginbutton.layer insertSublayer:layer atIndex:0];    return loginbutton;}

我需要自己处理突出显示吗?

解决方法 是的,您需要自己处理突出显示.你应该看看Jeff Lamarche非常容易使用 iPhone Gradient Buttons Project,而不是自己编写代码.它完全符合你的要求.它只是2个文件,因此很容易合并到您的项目中:

http://code.google.com/p/iphonegradientbuttons/source/browse/trunk/Classes/GradientButton.h
http://code.google.com/p/iphonegradientbuttons/source/browse/trunk/Classes/GradientButton.m

以下截图取自Jeff’s Blog discussing the project.

@H_403_2@ 总结

以上是内存溢出为你收集整理的ios – 如何使用渐变和突出显示创建UIButton?全部内容,希望文章能够帮你解决ios – 如何使用渐变和突出显示创建UIButton?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1053906.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-25
下一篇 2022-05-25

发表评论

登录后才能评论

评论列表(0条)

保存