Guest User

Untitled

a guest
May 21st, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.23 KB | None | 0 0
  1. //建立UIAlertController
  2. UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleAlert];
  3. UIAlertAction *defaultAction = [UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * action) {}];
  4. [alert addAction:defaultAction];
  5.  
  6. //Message排版
  7. NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
  8. paragraphStyle.alignment = NSTextAlignmentCenter;
  9. //Message1 置中
  10. NSMutableAttributedString *attributedStr = [[NSMutableAttributedString alloc] initWithString:@"Message1" attributes:@{NSParagraphStyleAttributeName:paragraphStyle}];
  11. NSMutableParagraphStyle *mParagraphStyle = [[NSMutableParagraphStyle alloc] init];
  12. mParagraphStyle.alignment = NSTextAlignmentLeft;
  13. //Message2 靠左
  14. NSMutableAttributedString *message = [[NSMutableAttributedString alloc] initWithString:@"\nMessage2-1\nMessage2-2\nMessage2-3\nMessage2-4" attributes:@{NSParagraphStyleAttributeName:mParagraphStyle}];
  15. [attributedStr appendAttributedString:message];
  16. [alert setValue:attributedStr forKey:@"attributedMessage"];
  17.  
  18. [self presentViewController:alert animated:YES completion:nil];
Add Comment
Please, Sign In to add comment