2016-08-24 2 views
-1

Swift 언어를 사용하여 프로그램에서 사용자 정의 경고를 프로그래밍 방식으로 구현해야합니다. 나는 몇몇 제 3 자 라이브러리 "SCLAlertView"를 사용하여 구현하려고 시도했지만 그 점을 이해할 수는 없지만, 애플리케이션의 버튼 변경 사항과 동적 메시지가있는 간단한 경고 팝업을 구현해야합니다. 내 앱에는 많은 AlertView가 있었기 때문에. 그래서 나는 동적으로 업데이 트해야합니다. 내가 그것을Swift 사용자 정의 경고보기 작성 방법

enter image description here

enter image description here

날이 기능을 구현하기 위해 도와주세요 구현하는 모양을 사용자 정의 경고의 샘플 이미지를 첨부 아래

.

+1

당신의 경고에 대한 사용자 정의 기능을 쉽게 사용할 수 있나요? 왜 당신은 정상적인'UIAlertController'를 사용할 수 없습니까? ('UIAlertView'는 더 이상 사용되지 않습니다). – rmaddy

답변

1

원할 때마다 다른 UIAlertAction을 UIAlertController에 추가하기 만하면됩니다.

let alertAction: UIAlertAction = UIAlertAction(title: "YES", style: UIAlertActionStyle.Default, handler: { 
    //Code goes here 
}) 

let alertAction2: UIAlertAction = UIAlertAction(title: "NO", style: UIAlertActionStyle.Default, handler: { 
    //Code goes here 
}) 

let alertAction3: UIAlertAction = UIAlertAction(title: "Maybe", style: UIAlertActionStyle.Default, handler: { 
    //Code goes here 
}) 

alert.addAction(alertAction) 
alert.addAction(alertAction2) 
alert.addAction(alertAction3) 

필요에 따라 UIAlertAction을 UIAlertController에 동적으로 추가 할 수 있습니다. 두 개의 버튼 만 필요한 경우 alertAction3을 추가하지 마십시오. 3 ~ 4 명이 필요한 경우 필요에 따라 추가하십시오. 당신이 열거

enum SCLAlertViewStyle: Int { 
     case Success, Error, Notice, Warning, Info, Edit, Wait 
    } 

    public enum SCLAnimationStyle { 
     case NoAnimation, TopToBottom, BottomToTop, LeftToRight, RightToLeft 
    } 

SCLAlertView와 Alert view StyleAlert View Animation 스타일을 선택할 수 있습니다 pod SCLAlertView

로 설치 포드 후

1

많은 제어 그룹이

여기

은이다에 textField, 버튼 및 아이콘을 추가하고자있다 버튼 기능 코드 추가

let alertView = SCLAlertView() 
alertView.addButton("First Button", target:self, selector:Selector("firstButton")) 
alertView.addButton("Second Button") { 
    println("Second button tapped") 
} 
alertView.showSuccess("Button View", subTitle: "This alert view has buttons") 

및 경고보기 사용자 정의 유형

SCLAlertView().showError("Hello Error", subTitle: "This is a more descriptive error text.") // Error 
SCLAlertView().showNotice("Hello Notice", subTitle: "This is a more descriptive notice text.") // Notice 
SCLAlertView().showWarning("Hello Warning", subTitle: "This is a more descriptive warning text.") // Warning 
SCLAlertView().showInfo("Hello Info", subTitle: "This is a more descriptive info text.") // Info 
SCLAlertView().showEdit("Hello Edit", subTitle: "This is a more descriptive info text.") // Edit 

Github의 페이지에 당신이 많은 아름 다운 종로 경고 뷰를 발견 할 것이다,

https://github.com/vikmeup/SCLAlertView-Swift