开发者

customized alert color and increase its frame depending on text input

I am adding a customized alert view and want to ch开发者_开发技巧ange its color to yellow with a textview in it.For this there is a property where we pass the name of a transparent image of that color and alert picks up that color.Also i want to increase the size of alert dynamically depending on the text in textview Any help would be appreciated

Thanks Vikas


changed the color with below code .But how to dismiss alert

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"UIAlert View" message:@"hello" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Close",nil];

UIImage *alertImage = [UIImage imageNamed:@"plus.png"];

UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:alertImage];

backgroundImageView.frame = CGRectMake(0, 0, 282, 130);

backgroundImageView.contentMode = UIViewContentModeScaleToFill;

[alert addSubview:backgroundImageView];

[alert sendSubviewToBack:backgroundImageView]; 
[alert show];
[alert release];


you can use this code to customize your uialertview..
You can take out the subviews of uialertview and can customize it any way you want.
Here is the code I used to customize the uialertivew
==========



-(void)willPresentAlertView:(UIAlertView *)alertView{
    for(UIView *view in alertView.subviews){
        view.backgroundColor= [UIColor clearColor];
    }
    UILabel *title = [alertView valueForKey:@"_titleLabel"];
    title.font = [UIFont fontWithName:@"Gibson-Regular" size:15.0];
    [title setTextColor:[UIColor whiteColor]];// set title color and font

    UILabel *body = [alertView valueForKey:@"_bodyTextLabel"];
    body.font = [UIFont fontWithName:@"Gibson-Regular" size:15.0];
    [body setTextColor:[UIColor whiteColor]];//set body color and font

    //after giving 12345 tag to your alert
    UITextView *txtBody=(UITextView*)[alertView viewWithTag:12345];
    if(txtBody){//scrollable
        txtBody.scrollEnabled = NO;
        CGRect frame  = txtBody.frame;
        frame.origin = CGPointMake(0, 0);
        UITextView *txtView = [[UITextView alloc]initWithFrame:frame];
        txtView.editable = NO;
        txtView.text = txtBody.text;
        txtView.font = [UIFont fontWithName:@"Gibson-Regular" size:15.0];
        [txtView setTextColor:[UIColor whiteColor]];
        [txtBody addSubview:txtView];
        txtBody.text=@"";

    }
    NSLog(@"%@",txtBody.subviews);
    for(UIView *view in txtBody.subviews){
        view.backgroundColor= [UIColor clearColor];
    }

    //    alertView.backgroundColor=[UIColor redColor];
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜