UIAlertView添加其它控件

本文介绍如何使用Objective-C来自定义UIAlertView的样式,包括标题、内容、复选框等元素的设置方法,并提供完整的代码示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.先上个效果图



2.再贴上实现代码

- (IBAction)btnClick:(id)sender

{

    //设置标题的时候最为关键,插入N个换行符留出足够控件

    UIAlertView *alert = [[UIAlertViewalloc]initWithTitle:@"这是标题\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n"

                                                    message:nil

                                                   delegate:self

                                          cancelButtonTitle:nil

                                          otherButtonTitles:@"确定",nil];

    

    //内容

    UILabel *lblAnnounce = [[UILabelalloc]initWithFrame:CGRectMake(20,32,250, 300)];

    lblAnnounce.backgroundColor = [UIColorclearColor];

    lblAnnounce.textColor = [UIColorwhiteColor];

    lblAnnounce.font = [UIFontsystemFontOfSize:15.0f];

    lblAnnounce.numberOfLines = 0;//上面两行设置多行显示

    lblAnnounce.text =@"文字内容,随便你添加什么\n1.这是第一行;\n2.这是第二行;\n3.这是第三行;\n4.你想加多少行都行!";

    

    //已阅读和不再提示

    CGRect cbReadFrame = CGRectMake(20,337,250, 18);

    SSCheckBoxView *cbRead = [[SSCheckBoxViewalloc]initWithFrame:cbReadFramestyle:kSSCheckBoxViewStyleGlossychecked:YES];

    [cbRead setText:@"已阅读并同意"];

    

    CGRect cbNeverPromptFrame = CGRectMake(20, 355, 250, 18);

    SSCheckBoxView *cbNeverPrompt = [[SSCheckBoxViewalloc]initWithFrame:cbNeverPromptFramestyle:kSSCheckBoxViewStyleGlossychecked:YES];

    [cbNeverPrompt setText:@"下次不再提示"];


    [alert addSubview:lblAnnounce];

    [alert addSubview:cbNeverPrompt];

    [alert addSubview:cbRead];

    [lblAnnounce release];

    [cbRead release];

    [cbNeverPrompt release];

    [alert show];

    [alert release];

}


3.另外如果想要checkbox的类的话可以在本站http://download.youkuaiyun.com/detail/sergiowoo/5165349找到,如果你没有积分了,发个email给我说明你想要的:SergioWoo@163.com


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值