ios,swift2020. 1. 31. 10:45

[ios]swift uitextview keyboard done 

 

uitextview hite keyboard 시키고 싶다..

 

그럴려면..

 

extension UITextField

{

    func addDoneButton(title: String, target: Any, selector: Selector) {

        

        let toolBar = UIToolbar(frame: CGRect(x: 0.0,

                                              y: 0.0,

                                              width: UIScreen.main.bounds.size.width,

                                              height: 44.0))//1

        let flexible = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)//2

        let barButton = UIBarButtonItem(title: title, style: .plain, target: target, action: selector)//3

        toolBar.setItems([flexible, barButton], animated: false)//4

        self.inputAccessoryView = toolBar//5

    }

}

 

self.mEtTextField.addDoneButton(title: "Done", target: self, selector: #selector(clickDone(sender:)))

 

@objc func clickDone(sender: Any) {

        self.view.endEditing(true)

    }

 

 

[참조] http://www.swiftdevcenter.com/uitextview-dismiss-keyboard-swift/

Posted by thdeodls85
ios,swift2020. 1. 31. 10:45

[ios] swift html 적용시키기

 

guard let text = "ㅁㅁㅁㅁㅁㅁ.<br><br>ㅠㅠㅠㅠㅠ".data(using: String.Encoding.unicode) else {

            return

        }

        try? mTvText.attributedText = NSAttributedString(data: text, options: [.documentType:NSAttributedString.DocumentType.html], documentAttributes: nil)

        self. mTvText.sizeToFit()

Posted by thdeodls85
ios,swift2020. 1. 31. 10:44

[ios] swift NSMutableAttributedString color 부분변경방법

 

글자의 range만 정해서 색상을 변경하고 싶다면???

 

let attributedString = NSMutableAttributedString(string: "qwerqweqweqweqwe")

 

attributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: UIColor(red: 0/255, green: 202/255, blue: 93/255, alpha: 255/255), range: NSRange(location: 0, length: 3))

        self.mTvText.attributedText = attributedString

func addAttribute(_ name: NSAttributedString.Key, value: Any, range: NSRange)

key 와 value넣고. range 영역 설정해주면..된다 ..

 

 

 

Posted by thdeodls85
ios,swift2020. 1. 30. 18:38

[ios]swift linker command failed with exit code 1 해결방법

 

Build Phases > Compile Sources 에서 추가한 라이브러리를 추가시켜주면된다.

 

[참조]

https://byunsooblog.wordpress.com/2014/01/14/error-linker-command-failed-with-exit-code-1/comment-page-1/

Posted by thdeodls85
ios,swift2020. 1. 30. 18:37

<html>

    

    <body>

        

        <script>

            

            alert("Hello, world!");

            

            </script>

        

    </body>

    

</html>

 

 

WKUIDelegate -> delegate 등록 시켜주고

 

@IBOutlet weak var webKitView: WKWebView!

 

override func viewDidLoad() {

 

        super.viewDidLoad()

 

webKitView.uiDelegate = self

}

 

 

 // java alert

    func webView(_ webView: WKWebView, runJavaScriptAlertPanelWithMessage message: String, initiatedByFrame frame: WKFrameInfo, completionHandler: @escaping () -> Void) {

        print("message ->\(message)")

        self.showToast(message: message)

        completionHandler()

    }

 

completionHandler() 꼭 해야 한다... 않하면 

 

runJavaScriptAlertPanelWithMessage:initiatedByFrame was not called -> 이런 이슈가 나온다

Posted by thdeodls85
ios,swift2020. 1. 30. 11:55

[ios] swift String trim방법

 

let keyword :  String = " a b "

 

keyword.trimmingCharacters(in: .whitespacesAndNewlines))

Posted by thdeodls85
ios,swift2020. 1. 30. 11:53

[ios] swift click animation 사라지게 하기

 

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        tableView.deselectRow(at: indexPath, animated: true)

}

Posted by thdeodls85
ios,swift2020. 1. 30. 10:34

[ios]swift String으로 Data타입 만들어서 JsonDecoder하는 방법

 

if let messageJson = content.message as String?

        {

            do

            {

                if let data : Data = messageJson.data(using: String.Encoding.utf8) ?? nil

                {

                    let message : Message = try JSONDecoder().decode(Message.self, from: data)

                    cell.mTvMessage.text = message.message

                }

                else

                {

                    cell. mTvMessage.text = ""

                }

            }catch

            {

                cell. mTvMessage.text = ""

            }

        }

 

string.data(using: String.Encoding.utf8) -> JsonDecoder().decode 하면 된다.

'ios,swift' 카테고리의 다른 글

[ios] swift String trim방법  (0) 2020.01.30
[ios] swift click animation 사라지게 하기  (0) 2020.01.30
[ios] swift dynamic height cell site  (0) 2020.01.30
[ios] example site  (0) 2020.01.30
[ios] swift textfield 직접 입력하기  (0) 2020.01.30
Posted by thdeodls85