Tuesday, 27 August 2013

Customise UIAlert View _bodyTextLabel text with NSAttributed String?

Customise UIAlert View _bodyTextLabel text with NSAttributed String?

My question is about Alert view. In my app I want to show a Disclaimer and
for this i'm using an UIAlertView. I used the delegate method of AlertView
and the NSAttributted String in my code, the problem is that i want to set
the Disclaimer message as colourful. The Title is customised but the
message doesn't have any effect.
Can any one help..! i posting the code.
http://i.stack.imgur.com/pCWVk.png
code:
//UIAlert View Method// -(void)willPresentAlertView:(UIAlertView
*)alertView {
UILabel *title = [alertView valueForKey:@"_titleLabel"];
UIColor *_green=[UIColor colorWithPatternImage:[UIImage
imageNamed:@"tab_strip@2x.png"]];
NSShadow *shadowDic=[[NSShadow alloc] init];
[shadowDic setShadowBlurRadius:5.0];
[shadowDic setShadowColor:[UIColor grayColor]];
[shadowDic setShadowOffset:CGSizeMake(0, 3)];
NSMutableAttributedString *attb_String=[[NSMutableAttributedString alloc]
initWithString:title.text];
[attb_String addAttribute:NSFontAttributeName value:[UIFont
fontWithName:@"HelveticaNeue-Bold" size:21.0] range:NSMakeRange(0, 1)];
[attb_String addAttribute:NSFontAttributeName value:[UIFont
fontWithName:@"HelveticaNeue-Bold" size:23.0] range:NSMakeRange(0,
title.text.length)];
[attb_String addAttribute:NSStrokeColorAttributeName value:_green
range:NSMakeRange(0, title.text.length)];
[attb_String addAttribute:NSStrokeWidthAttributeName value:[NSNumber
numberWithFloat:3.0] range:NSMakeRange(0, title.text.length)];
[attb_String addAttribute:NSShadowAttributeName value:shadowDic
range:NSMakeRange(0, title.text.length)];
[attb_String addAttribute:NSStrokeWidthAttributeName value:[NSNumber
numberWithFloat:-3.0] range:NSMakeRange(0, title.text.length)];
title.attributedText=attb_String;
UILabel *body = [alertView valueForKey:@"_bodyTextLabel"];
[body setAdjustsLetterSpacingToFitWidth:YES];
[body setAdjustsFontSizeToFitWidth:YES];
NSLog(@"body value=%d",body.text.length);
NSMutableAttributedString *attb_BodyString=[[NSMutableAttributedString
alloc] initWithString:body.text];
[attb_BodyString addAttribute:NSFontAttributeName value:[UIFont
fontWithName:@"HelveticaNeue-Bold" size:28.0]
range:NSMakeRange(0,body.text.length)];
[attb_BodyString addAttribute:NSStrokeColorAttributeName value:_green
range:NSMakeRange(0, body.text.length)];
// NSMutableParagraphStyle *paragrahStyle = [[NSMutableParagraphStyle
alloc] init]; // [paragrahStyle setAlignment:NSTextAlignmentCenter]; //
[attb_BodyString addAttribute:NSParagraphStyleAttributeName
value:paragrahStyle range:NSMakeRange(0, body.text.length)];
//[body setMinimumScaleFactor:15.0/body.font.pointSize];
//[body setLineBreakMode:NSLineBreakByWordWrapping];
body.attributedText=attb_BodyString;
}
and i also want to use the NSMutableParagraphStyle but it throws the error
"NSAttributedString invalid for autoresizing, it must have a single
spanning paragraph style (or none) with a non-wrapping lineBreakMode"

No comments:

Post a Comment