现在的位置: 首页 > 综合 > 正文

解决ios7以上版本UIAlertView调用addSubview无效问题

2018年04月05日 ⁄ 综合 ⁄ 共 746字 ⁄ 字号 评论关闭

解决ios7以上版本UIAlertView的addSubview函数无效问题

如下代码增加两个文本框效果

- (IBAction)add:(id)sender {
    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"添加明星阵容" message:nil delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"添加", nil];
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(180, 5, 85, 75)];
    UITextField *tf = [[UITextField alloc]initWithFrame:CGRectMake(0,0,400, 35)];
    UITextField *tf2 = [[UITextField alloc]initWithFrame:CGRectMake(0,37,400, 35)];
    tf.backgroundColor = [UIColor whiteColor];
    tf2.backgroundColor = [UIColor whiteColor];
    [view addSubview:tf];
    [view addSubview:tf2];
    
    //check if os version is 7 or above
    if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
       [alertView setValue:view forKey:@"accessoryView"];
    }else{
        [alertView addSubview:view];
    }

    [alertView show];
}

抱歉!评论已关闭.