반응형

Creating a Glow Effect for UILabel and UIButton

One recent iPhone design mockup called for a glowing effect for a UIButton.

This can be accomplished with images, however I needed a series of buttons to have the same glow effect, and it can easily be accomplished with Core Graphics.

The first step is to include the Core Graphics headers:

1
#import <QuartzCore/QuartzCore.h>

Next, the effect is achieved by using a shadow with no offset (meaning the shadow will be directly underneath the text, not shifted down or to the right). The layer is then given a shadow radius & opacity to allow the shadow to bleed outward. Unsetting masksToBounds will allow the glow to be drawn even outside of the label’s frame. Finally the shadow color is set to either the foreground color or something a bit lighter.

1
2
3
4
5
6
UIColor *color = button.currentTitleColor;
button.titleLabel.layer.shadowColor = [color CGColor];
button.titleLabel.layer.shadowRadius = 4.0f;
button.titleLabel.layer.shadowOpacity = .9;
button.titleLabel.layer.shadowOffset = CGSizeZero;
button.titleLabel.layer.masksToBounds = NO;

This effect works on plain UILabel or the titleLabel property of a UIButton. You can see the results of the effect here:

Don’t go overboard with this. It’s a subtle effect, but looks great when used effectively.


반응형

'IPHONE' 카테고리의 다른 글

Alpha 값 적용된 이미지 얻기.  (0) 2013.11.09
UIButton 텍스트 정렬 및 코너 라운드 처리 하기.  (0) 2013.11.06
scrollView 코드로 이동하기.  (0) 2013.10.25
UIColor 유용한 카테고리.  (0) 2013.10.17
ios Localization.  (0) 2013.10.11
Posted by 컴스터
,