alertMessage 왼쪽 정렬

2017. 2. 15. 13:29Programming/Swift

반응형
 - 변경 전

let alertController = UIAlertController(title: "삭제 하시겠습니까?", message: "사용자: \(username)"+"\n"+"휴대폰: \(phone)"+"\n"+"네이트온: \(nateon)", preferredStyle: .alert)

            

let submit = UIAlertAction(title: "Submit", style: UIAlertActionStyle.default, handler: { (paramAction:UIAlertAction) in

    if let status = self.ArrayUserName[indexPath.row].authstatus, let auth = self.ArrayUserName[indexPath.row].authvalue {

        self.ProcessData(flag: "delete", authvalue: auth, authstatus: status)

    }

        self.ArrayUserName.remove(at: indexPath.row)

        tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)

    })


    let cancel = UIAlertAction(title:"Cancel", style:UIAlertActionStyle.cancel, handler:nil)

            

    alertController.addAction(submit)

    alertController.addAction(cancel)

    self.present(alertController, animated: true, completion: nil)



 - 변경 후

let userMessage = "사용자: \(username)"+"\n"+"휴대폰: \(phone)"+"\n"+"네이트온: \(nateon)"

let alertController = UIAlertController(title: "삭제 하시겠습니까?", message: userMessage, preferredStyle: .alert)

            

let submit = UIAlertAction(title: "Submit", style: UIAlertActionStyle.default, handler: { (paramAction:UIAlertAction) in

    if let status = self.ArrayUserName[indexPath.row].authstatus, let auth = self.ArrayUserName[indexPath.row].authvalue {

        self.ProcessData(flag: "delete", authvalue: auth, authstatus: status)

    }

                

        self.ArrayUserName.remove(at: indexPath.row)

         tableView.deleteRows(at: [indexPath], with: UITableViewRowAnimation.automatic)

     })

    let cancel = UIAlertAction(title:"Cancel", style:UIAlertActionStyle.cancel, handler:nil)

            

    let paragraphStyle = NSMutableParagraphStyle()

    paragraphStyle.alignment = NSTextAlignment.left

            

    let messageText = NSMutableAttributedString(

        string: userMessage,

        attributes: [

            NSParagraphStyleAttributeName: paragraphStyle,

            NSFontAttributeName: UIFont.systemFont(ofSize: 15.0)

         ]

    )

    alertController.setValue(messageText, forKey: "attributedMessage")        

    alertController.addAction(submit)

    alertController.addAction(cancel)

    self.present(alertController, animated: true, completion: nil) 


반응형