自定义警报颜色并根据文本输入增加其框架

发布于 2024-12-05 16:26:14 字数 132 浏览 1 评论 0原文

我正在添加一个自定义的警报视图,并希望将其颜色更改为黄色,并在其中包含一个文本视图。为此,有一个属性,我们可以传递该颜色的透明图像的名称,警报会拾取该颜色。我也想根据文本视图中的文本动态增加警报的大小 任何帮助将不胜感激

谢谢 维卡斯

I am adding a customized alert view and want to change 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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

猫卆 2024-12-12 16:26:14

使用下面的代码更改了颜色。但是如何消除警报

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];

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];
愁以何悠 2024-12-12 16:26:14
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];
}
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];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文