Create glowing text effect on iOS

前端 未结 2 1997
栀梦
栀梦 2020-12-31 18:45

We\'re currently building an iPhone app and would like the text to have a glowing effect to fit in with the realistic UI design.

Here is what we\'re trying to achiev

相关标签:
2条回答
  • 2020-12-31 19:38

    To set up the button with the text colored #98c1c1, use:

    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 60)];
    label.textColor = [UIColor colorWithRed:((float)152/255) green:((float) 193/255) blue:((float) 193/255) alpha:1.0f];
    

    I used Photoshop to find RGB components of #98c1c1, which ended up being R:152 G:193 B:193. And colorWithRed:green:blue:alpha: takes a normalized value between 0 and 1, and that's why I made it the RGB value over 255.

    For the outer glow, use:

    label.layer.shadowColor = [UIColor whiteColor].CGColor;
    label.layer.shadowOffset = CGSizeMake(0.0, 0.0);    
    label.layer.shadowRadius = 10.0;
    label.layer.shadowOpacity = 0.3;
    label.layer.masksToBounds = NO;
    

    You want the opacity to be 30% and the shadow color #ffffff (white). That is why label.layer.shadowOpacity is set to 0.3 (30%) and label.layer.shadowColor is set to white.

    I'm not quite sure about how to implement the inner glow, but you could possibly create a method that duplicates the text but makes the font smaller and centers the new text, to create the effect of an inner glow. Remember to import <Quartzcore/Quartzcore.h>!

    0 讨论(0)
  • 2020-12-31 19:38

    Updating the code posted by pasawaya:

    label.layer.shadowColor = ([UIColor .green] as! CGColor)
    label.layer.shadowOffset = CGSize.zero
    label.layer.shadowRadius = 10.0;
    label.layer.shadowOpacity = 0.
    label.layer.masksToBounds = false
    
    0 讨论(0)
提交回复
热议问题