Wednesday 5 December 2018

Remove bottom line in navigation bar


navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .any, barMetrics: .default)
        
navigationController?.navigationBar.shadowImage = UIImage()

Remove text from Back button in navigation bar



copy this line in where you are navigating from,  means here ( MapView Controller )

navigationItem.backBarButtonItem = UIBarButtonItem(title: "", style: .plain, target: nil, action: nil)

Map View text will remove

Wednesday 13 June 2018

UILabel padding


class paddingLabel: UILabel {
    let topInset = CGFloat(20)
    let bottomInset = CGFloat(20)
    let leftInset = CGFloat(20)
    let rightInset = CGFloat(20)
    
    override func drawText(in rect: CGRect) {
        let insets: UIEdgeInsets = UIEdgeInsets(top: topInset, left: leftInset, bottom: bottomInset, right: rightInset)
        super.drawText(in: UIEdgeInsetsInsetRect(rect, insets))
    }
    
    override public var intrinsicContentSize: CGSize {
        var intrinsicSuperViewContentSize = super.intrinsicContentSize
        intrinsicSuperViewContentSize.height += topInset + bottomInset
        intrinsicSuperViewContentSize.width += leftInset + rightInset
        return intrinsicSuperViewContentSize
    }
}

Add this class to UILable

Sunday 20 May 2018

Reading data from Local Json file using Alamofire in swift3


//Reading data from Local Json file instead of Service urls using Alamofire in swift3


func getwordmeaningdata()
  {
   
    if let path = Bundle.main.path(forResource: "localfile", ofType: "json") {
       let url=URL(fileURLWithPath: path)
        Alamofire.request(url).responseJSON { response in
            
            if let JSON = response.result.value {
                print("JSON: \(JSON)") 
            }
        }
}


//This is the data of local json file not getting from URL
localfile.json


{
  "person":[
    {
      "name": "Bob"
     
    },
    {
      "name": "Vinny"
      }

]
}

Tuesday 15 May 2018

Read data from textfile in swift 3


let path = Bundle.main.path(forResource: "textfile", ofType: "txt")
 print(path!)
                
let url = URL(fileURLWithPath: path!)
 print(url)
                
 let contentString:String = try! String(contentsOf: url, encoding: String.Encoding(rawValue: String.Encoding.utf8.rawValue))

//if convert to Data

 let data = contentString.data(using: String.Encoding(rawValue: String.Encoding.utf8.rawValue), allowLossyConversion: false)!
                        

print("string\(contentString)")


Wednesday 21 March 2018

Localization in swift 3

step 1 : Add the Language





-->file will added like above image

Step - 2 : Add the String file

create String file and rename it as "Localizable.strings"





Step 3 : Configure String file for Localization



Step - 4 : Add the key values to get the value



note: we may check files are created in currect format or not by using cmds
  1. cd into your project root
  2. cd en.lproj - you can replace this with any localisation you are working with.
  3. plutil -lint Localizable.strings

step - 5:

we can switch the language on buttons like


  @IBAction func english(_ sender: Any) {
        
        let path = Bundle.main.path(forResource: "en", ofType: "lproj")
        let bundel = Bundle.init(path:path!)! as Bundle
   countryName.text=bundel.localizedString(forKey: "usernametitle", value: nil, table: nil)
    }
    //pt-PT.lproj

    @IBAction func protual(_ sender: Any) {
        let path = Bundle.main.path(forResource: "pt-PT", ofType: "lproj")
        let bundel = Bundle.init(path:path!)! as Bundle
        countryName.text=bundel.localizedString(forKey: "usernametitle", value: nil, table: nil)
    }



change forResource string based on language



Remove bottom line in navigation bar

navigationController ?. navigationBar . setBackgroundImage ( UIImage (), for: . any , barMetrics: . default )          navigat...