Posts

Showing posts from January, 2018

Remove the extra pasted text textview swift || UITextview character count when copy paste iOS swift || substring for limiting characters swift

SOLUTION: Use the textview delegate method to control the user input within your Limit. Inside the below delegate method do the process.It will control the text entry in all scenarios like user typing text or copy pasted text.     func textView( _ textView: UITextView ,                   shouldChangeTextIn range: NSRange ,                    replacementText text: String ) -> Bool { //this part is used for get the user inputstring and also the previously entered string         var nsString: NSString = ""                  if textView. text != nil   && text != "" {             nsString = textView. text ! as NSString             nsString = nsString. replacingCharacters (in: range, with: text) as NSString         }   else if (text == "" ) && textView. text != ""   {             nsString = textView. text ! as NSString             nsString = nsString. replacingCharacters (in: range, with

iOS LocalNotification set to 30 secs

Solution: In iOS maximum sound time limit is 30 Sec.So if your sound file had that time duration then only it plays.Otherwise if your audio file is 0:31 also not able to play. If the app is in background or terminated state and device is locked then it will ring 30secs.If the screen is on then it should play the sound until the drop down message goes Up.It was not the problem it was handled by the OS.

Move the view Up when keyboard shows in iOS swift.

Solution: If you are tried to edit the textField but keyboard came up and hides the TextField. Don't worry here below the code will broken your headache.It will up the view when the keyboard came to visible. In ViewdidLoad add the below code          NotificationCenter . default . addObserver ( self , selector: #selector ( ViewController . keyboardWillShow ), name: NSNotification . Name . UIKeyboardWillShow , object: nil )          NotificationCenter . default . addObserver ( self , selector: #selector ( ViewController . keyboardWillHide ), name: NSNotification . Name . UIKeyboardWillHide , object: nil ) Then implement the below methods to get the edit easy.     func keyboardWillShow(notification: NSNotification ) {         if let keyboardSize = (notification. userInfo ?[ UIKeyboardFrameBeginUserInfoKey ] as ? NSValue )?. cgRectValue {             if self . view . frame . origin . y == 0 {                 self . view . frame . origin . y -= keybo

iOS returnKey in Keyboard to hide the keyboard

Solution: The below code is used for hide the keyboard when the user touches the UITextField and started editing after that click the return Key.     func textFieldShouldReturn( _ textField: UITextField ) -> Bool {         self . view . endEditing ( true )         return false      }

Webview to show loading indicator for every click inside the webview swift

Solution: In the ViewController you have to implement the webView delegate methods as like below to achieve the every click action loader in the webView.      func webView( _ webView: UIWebView , shouldStartLoadWith request: URLRequest , navigationType: UIWebViewNavigationType ) -> Bool {          activityindicator . startanimating ( ) }       func webViewDidFinishLoad( _ webView: UIWebView ) {          activityindicator . stopanimating ( ) }      func webView( _ webView: UIWebView , didFailLoadWithError error: Error ) {          activityindicator . stopanimating ( ) }

How check webrequest is not http or https url in swift?

Solution: Here we will check that our web request url contains the "tel" or something else except http or https. In your webviewdelegate method you can write the below code and check.         let str = request. url ?. absoluteString          if str?. startIndex . d istance (to:str?. index (of: "tel" )) != 0 { }

Error : Binary operator '>=' cannot be applied to operands of type 'String.Index?' and 'Int' in swift

Solution: To find the index of substring in a string in a particular index.Here we had an example with "t" string is in 0th position. Code:         let str = request. url ?. absoluteString          if str?. startIndex . d istance (to:str?. index (of: "t" )) != 0 { }

How to get the UITextField Y axis Coordinate on UIView level

Solution :              let textFieldY = textField. convert (textField. frame . origin , to: self . view ). y The above will calculate the y position of the textfield that is inside the tableview cell from the UIView level.