4

I'm trying to get some of the text in "message" for my UIAlertView to be bold. Like this:

UIAlertView message: Header some text, new header some more text

I've tried with basic html formatting (since "/n" works for new line), but that doesn't work for me. Is there an easy way to get some of the text bold?

Of course, if there isn't i can always write a customized implementation for an alertview, but if there's an easier way i would appriciate if someone could tell me :)

Madoc
  • 1,605
  • 3
  • 17
  • 30
  • 1
    Im afraid the only way to get this it's going to be implementing your own alert view, if you need help with that let us know. – Antonio MG Mar 01 '12 at 10:35
  • 1
    You'll have to add some subviews or make your own alertView. [This link](http://stackoverflow.com/questions/5272326/uialertview-text-formatting) might help – tipycalFlow Mar 01 '12 at 10:36

4 Answers4

6

Here is the code you are looking for, without creating a custom alert

DOES NOT WORK ON iOS7

  UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"title" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
    UILabel *txtField = [[UILabel alloc] initWithFrame:CGRectMake(12.0, 25.0, 260.0, 95.0)];
    [txtField setFont:[UIFont fontWithName:@"Helvetica-Bold" size:(18.0)]];
    txtField.numberOfLines = 3;
    txtField.textColor = [UIColor redColor];
    txtField.text = @"Look at me, I am a Red and Bold Label.";
    txtField.backgroundColor = [UIColor clearColor];
    [alertView addSubview:txtField];
    [alertView show];
chewy
  • 8,207
  • 6
  • 42
  • 70
3

It's all good if your app running under iOS 6 or lower, but unfortunately you can't add subviews to your alert view in iOS7. So if you need only to show message with bold font and you're not interested in creating custom views, you can simply add your text to title, when message leave empty.

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Your message"
                                                    message:@""
                                                   delegate:nil
                                          cancelButtonTitle:@"OK"
                                          otherButtonTitles:nil];
[alertView show];
2
UILabel *alertMessage =  [alert.subviews objectAtIndex:1]; 
alertMessage.textColor = [UIColor redColor]
melgamal
  • 101
  • 11
2

In response to chewy's answer a textfield can be added to a UIAlertView in iOS7, just replace

[alertView addSubview:txtField];

with

[alertView setValue:txtField forKeyPath:@"accessoryView"];