【问题标题】:how to create UIButton shadow glow effect?如何创建 UIButton 阴影发光效果?
【发布时间】:2013-12-18 11:05:31
【问题描述】:

我创建了一个 UIButton 并使用 CAShapeLayer 和 UIBezierPath 添加了自定义层,用于制作按钮圆形。

在按钮点击功能中,我添加了发光效果阴影,但它不起作用。

按钮创建代码:

_closeButton = [UIButton buttonWithType:UIButtonTypeCustom];

_closeButton.frame = CGRectMake(6.0, 6.0, 20.0, 20.0);  

 CAShapeLayer *circleLayer = [CAShapeLayer layer];

[circleLayer setBounds:CGRectMake(0.0f, 0.0f, [_closeButton bounds].size.width,
                                          [_closeButton bounds].size.height)];

[circleLayer setPosition:CGPointMake(CGRectGetMidX([_closeButton bounds]),CGRectGetMidY([_closeButton bounds]))];

UIBezierPath *path = [UIBezierPath bezierPathWithOvalInRect:CGRectMake(0, 0, CGRectGetWidth(_closeButton.frame), CGRectGetHeight(_closeButton.frame))];

[circleLayer setPath:[path CGPath]];

[circleLayer setStrokeColor:[[UIColor whiteColor] CGColor]];

[circleLayer setLineWidth:2.50f];

[circleLayer setFillColor:[[UIColor blackColor] CGColor]];

[[_closeButton layer] addSublayer:circleLayer];

_closeButton.layer.cornerRadius = _closeButton.bounds.size.width / 2.0;

[_closeButton setTitle:@"X" forState:UIControlStateNormal];

_closeButton.titleLabel.textAlignment = NSTextAlignmentCenter;

[_closeButton.titleLabel setFont:[UIFont boldSystemFontOfSize:15.0]];

[_closeButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

[_closeButton addTarget:self action:@selector(closeButtonPressed) 

forControlEvents:UIControlEventTouchUpInside];

_qbWebView.scalesPageToFit = YES;

_activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];

_activityIndicator.hidesWhenStopped = YES;

[_qbView addSubview:_qbWebView];

[_qbView addSubview:_closeButton];

按钮点击功能

_closeButton.layer.shadowColor = [[UIColor whiteColor] CGColor];

_closeButton.layer.shadowRadius = 40.0f;

_closeButton.layer.shadowOpacity = .9;

_closeButton.layer.shadowOffset = CGSizeMake(40.0f, 40.0f);

_closeButton.layer.masksToBounds = NO;

很遗憾没有出现发光效果:(

【问题讨论】:

  • 此处发光表示您要突出显示按钮?
  • 是的,我想阴影环绕按钮的发光效果
  • @RakeshR _closeButton.showsTouchWhenHighlighted=YES;试试这个
  • @Minkle Garg _closeButton.showsTouchWhenHighlighted=YES;这个发光整个按钮。我需要显示带有阴影的按钮 .. 意味着按钮应该被发光包围,并且整个按钮仍然应该清晰可见
  • _closeButton.imageView.layer.cornerRadius = 7.0f; _closeButton.layer.shadowRadius = 3.0f; _closeButton.layer.shadowColor = [UIColor blackColor].CGColor; _closeButton.layer.shadowOffset = CGSizeMake(0.0f, 1.0f); _closeButton.layer.shadowOpacity = 0.5f; _closeButton.layer.masksToBounds = 否;检查这个

标签: ios iphone objective-c uibutton


【解决方案1】:
_closeButton.imageView.layer.cornerRadius = 7.0f; 
_closeButton.layer.shadowRadius = 3.0f; 
_closeButton.layer.shadowColor = [UIColor blackColor].CGColor;
_closeButton.layer.shadowOffset = CGSizeMake(0.0f, 1.0f); 
_closeButton.layer.shadowOpacity = 0.5f;
_closeButton.layer.masksToBounds = NO; 

检查一下

【讨论】:

    猜你喜欢
    • 2016-06-14
    • 1970-01-01
    • 2011-11-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多