Posts

Showing posts from September, 2018

how to set Image in circle in Swift

imgUserImage . layer . borderWidth = 0.01 imgUserImage . layer . borderColor = UIColor . white . cgColor imgUserImage . layer . cornerRadius =   imgUserImage . frame . width / 2 imgUserImage . layer . masksToBounds = true

How to Upload image Using Alamofire in Swift

First Install Pod :- "Alamofire" write this code in you file:-  Alamofire. upload (multipartFormData: { (multipartFormData) in             for (key, value) in parameters {                 print ( "Key \ ( key ) Value \ ( value )" )                 multipartFormData. append ( " \ ( value )" . data (using: String . Encoding . utf8 )!, withName: key as String )             }                          if arrFile. count > 0             {                 for i in 0 ..<arrFile. count                 {                     let dictTemp : NSMutableDictionary = arrFile. object (at: i) a...

How to set image according to imageView in swift

Copy and pest that function to your project manager or main file func imageAdjustAccordingSize( _ image: UIImage ?, size cgSize: CGSize ) -> UIImage ? {         let scale: CGFloat = max(cgSize.width / (image?.size.width ?? 0.0 ), cgSize.height / (image?.size.height ?? 0.0 ))         let width: CGFloat = (image?.size.width ?? 0.0 ) * scale         let height: CGFloat = (image?.size.height ?? 0.0 ) * scale         let imageRect = CGRect(x: (cgSize.width - width) / 2.0 , y: (cgSize.height - height) / 2.0 , width: width, height: height)         UIGraphicsBeginImageContextWithOptions(cgSize, false , 0 )         image?.draw(in: imageRect)         let newImage: UIImage ? = UIGraphicsGetImageFromCurrentImageContext()         UIGraphicsEndImageContext()         return newImage     ...

How can I set textview height according to your text in swift 4

  If you want to increases you textview height according to your text then do following steps. Create Hieght object   Like:-  @IBOutlet var consTxtdescHeight: NSLayoutConstraint !     func setTextViewHeight()     {         let fixedWidth = txtDesc.frame.size.width         txtDesc.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))         let newSize = txtDesc.sizeThatFits(CGSize(width: fixedWidth, height: CGFloat.greatestFiniteMagnitude))         var newFrame = txtDesc.frame         newFrame.size = CGSize(width: max(newSize.width, fixedWidth), height: newSize.height)         consTxtdescHeight.constant = newFrame.height      } Thank you Enjoy it.

How to add Attributed String in label.

let attributedStr = NSMutableAttributedString (string: "Hi " , attributes:[ NSAttributedStringKey . font : UIFont (name: FontName . OpenSans_Regular , size: FontSize . SIXTEEN )!, NSAttributedStringKey . foregroundColor : COLOR . Black ])                 let attributedStr1 = NSMutableAttributedString (string: "  My Name is " , attributes:[ NSAttributedStringKey . font : UIFont (name: FontName . OpenSans_Bold , size: FontSize . SIXTEEN )!, NSAttributedStringKey . foregroundColor : COLOR . Blue ])                 let attributedStr2 = NSMutableAttributedString (string: "Harsh " , attributes:[ NSAttributedStringKey . font : UIFont (name: FontName . OpenSans_Regular , size: FontSize . SIXTEEN )!, NSAttributedStringKey . foregroundColor : COLOR . Green ])                 let attributedStr3 = NSMutableAttributedString (string: "How are ...

How to Call API in swift using Alamofire

if you first time call API in your App than add it in you Info.plist <key> NSAppTransportSecurity </key> <dict> <key> NSAllowsArbitraryLoads </key> <true/> </dict> than install pod 'Alamofire' and import it like: Code : import Alamofire func callAPINoParameters()     {         let strURL =  yourURL                  Alamofire. request (strURL). responseJSON { (response) in             switch response. result {             case . success ( let JSON):                                  let response = JSON as ! NSDictionary                 print (response)               ...