2016-06-08 59 views
1

我需要添加一些标签UIAlertController和研究后证明,没有正常的方法来做到这一点。但由于可以添加UITextField,我决定将UITextField的外观更改为UILabel(没有边框和背景颜色)。但改变其背景颜色清晰和边框样式没有帮助。我怎样才能做到这一点?
下面是代码:UIAlertController或UITextField UILabel UILabel

- (void)test 
{ 
    UIAlertController * alert = [UIAlertController alertControllerWithTitle:@"Test Title" 
                    message:@"Test Message" 
                  preferredStyle:UIAlertControllerStyleAlert]; 

    UIAlertAction* ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault 
               handler:^(UIAlertAction * action) { 
                //Do Some action here 

               }]; 
    UIAlertAction* cancel = [UIAlertAction actionWithTitle:@"Cancel" style:UIAlertActionStyleDefault 
                handler:^(UIAlertAction * action) { 
                 [alert dismissViewControllerAnimated:YES completion:nil]; 
                }]; 

    [alert addAction:ok]; 
    [alert addAction:cancel]; 
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
     textField.text = @"Text: "; 
     textField.backgroundColor = [UIColor blueColor]; 
     textField.borderStyle = UITextBorderStyleNone; 
     textField.backgroundColor = [UIColor clearColor]; 
     [textField setUserInteractionEnabled:NO]; 
    }]; 
    [alert addTextFieldWithConfigurationHandler:^(UITextField *textField) { 
    }]; 

    [self presentViewController:alert animated:YES completion:nil]; 
} 

更新:
这里是我所得到的:
What I have
这里是我想要做:
What I trying to do

+0

不中UIAlert消息像一个标签。你基本上想在UIAlert中使用一个自定义标签,以便你可以自定义它的属性(改变字体,颜色等)?请让我知道 – KrishnaCA

+0

@Chaitanya我已更新我的问题。在那里你可以看到我想要做的事情。 –

回答

0

使用本

textField.placeholder = @"Text: "; 

代替

textField.text = @"Text: "; 
+0

感谢您的回答,但这并没有帮助 –

+0

为什么您要添加标签? –