我在 .h 文件中有以下代码:
#import <UIKit/UIKit.h>
@interface SCLoginViewController : UIViewController
@property (weak, nonatomic) IBOutlet UIButton *btnLogin;
@end
以及 .m 文件中的以下代码:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
// Do any additional setup after loading the view from its nib.
// Add gradient to the buttons
btnLogin.layer.cornerRadius = 10;
CAGradientLayer *gradientLayer = [CAGradientLayer layer];
gradientLayer.frame = btnLogin.layer.bounds;
gradientLayer.colors = [NSArray arrayWithObjects:
(id)[UIColor colorWithWhite:1.0f alpha:0.1f].CGColor,
(id)[UIColor colorWithWhite:0.4f alpha:0.5f].CGColor,
nil];
gradientLayer.cornerRadius = btnLogin.layer.cornerRadius;
[btnLogin.layer addSublayer:gradientLayer];
// Add shadow
btnLogin.layer.shadowColor = [UIColor darkGrayColor].CGColor;
btnLogin.layer.shadowOpacity = 1.0;
btnLogin.layer.shadowOffset = CGSizeMake(2.0, 2.0);
}
这是按钮在屏幕上的显示方式:
不过,有些事情是非常错误的。我知道我错过了一些简单的东西,但无法弄清楚。我创建了名为 btnLogin 的常规插座,但我尝试对其进行的任何更改都不起作用。该按钮是圆角矩形按钮。我尝试了自定义按钮,但没有帮助。
谢谢!