ios - Adding two shadows to a UILabel -
i have uilabel
want add 2 shadows.
a black colored shadow, , white colored one.
one has -1 y-offset, , other has 1 y-offset.
- (void)layoutsubviews{ [super layoutsubviews]; self.sectiontitlelabel.layer.shadowcolor = [[uicolor whitecolor] cgcolor]; self.sectiontitlelabel.layer.shadowradius = 0.0f; self.sectiontitlelabel.layer.shadowopacity = .2; self.sectiontitlelabel.layer.shadowoffset = cgsizemake(0.f, -1.f); calayer *blackshadow = [[calayer alloc] initwithlayer:self.sectiontitlelabel.layer]; blackshadow.shadowcolor = [[uicolor blackcolor] cgcolor]; blackshadow.shadowradius = 0.0f; blackshadow.shadowopacity = .4; blackshadow.shadowoffset = cgsizemake(0.f, 1.f); [self.sectiontitlelabel.layer addsublayer:blackshadow]; self.sectiontitlelabel.layer.maskstobounds = no; }
with white shadow appears, black 1 not.
i don't understand mean "two shadows uilabel" hope can help. if on picture can see want, happy :)
- (void)viewdidload { [super viewdidload]; nsmutableattributedstring* attstring = [[nsmutableattributedstring alloc] initwithstring:self.custlabel.text]; nsrange range = nsmakerange(0, [attstring length]); [attstring addattribute:nsfontattributename value:self.custlabel.font range:range]; [attstring addattribute:nsforegroundcolorattributename value:self.custlabel.textcolor range:range]; nsshadow* shadow = [[nsshadow alloc] init]; shadow.shadowcolor = [uicolor whitecolor]; shadow.shadowoffset = cgsizemake(0.0f, 1.0f); [attstring addattribute:nsshadowattributename value:shadow range:range]; self.custlabel.attributedtext = attstring; [self nextshadow]; } -(void)nextshadow { self.custlabel.layer.maskstobounds = no; self.custlabel.layer.cornerradius = 5; self.custlabel.layer.shadowoffset = cgsizemake(3, 0); self.custlabel.layer.shadowradius = 5; self.custlabel.layer.shadowopacity = 1.5; }
i'd try use
- (void)addattributes:(nsdictionary *)attrs range:(nsrange)range;
but can't use 2 shadow attributes, one. , can customize
-(void)nextshadow
method create solution, example
-(void)nextshadow { self.custlabel.layer.maskstobounds = no; self.custlabel.layer.cornerradius = 1; self.custlabel.layer.shadowoffset = cgsizemake(1, 0); self.custlabel.layer.shadowradius = 1; self.custlabel.layer.shadowopacity = 1.5; }
if adjust values in -(void)nextshadow can want.
Comments
Post a Comment