@IBOutlet var userPhoneNumber: UITextField!



    override func viewDidLoad() {

        super.viewDidLoad()


       

// touch (start editing)

        userPhoneNumber.addTarget(self, action: #selector(self.myTouchEvent), for: UIControlEvents.editingDidBegin)

        



// end editing

        userPhoneNumber.addTarget(self, action: #selector(self.myEndTouchEvent), for: UIControlEvents.editingDidEnd)

        

        

    }




    func myTouchEvent(textfield: UITextField) {

        print("textfield touched")


    }


    func myEndTouchEvent(textfield: UITextField) {

        print("textfield edit end")


    }

블로그 이미지

엘로드넷

댓글을 달아 주세요

Swift3  UserDefaults 에 이미지 저장하고 꺼내기


//이미지 저장

        

let testImage = UIImage(named: "testimgae")

        

let jpgImage = UIImageJPEGRepresentation(testImage, 0.1)        // 10분의 1로 축소

        

UserDefaults.standard.set(jpgImage, forKey: "profileImage")

UserDefaults.standard.synchronize()

        




//이미지 꺼내기


@IBOutlet var profileImage: UIImageView!


override func viewWillAppear(_ animated: Bool) {

   if let imgData = UserDefaults.standard.object(forKey: "profileImage") as? NSData

   {

       if let image = UIImage(data: imgData as Data)

       {

                self.profileImage.image = image


       }

   }


}

블로그 이미지

엘로드넷

댓글을 달아 주세요

resign keyboard textfield

iOS Swift 2016. 12. 31. 16:37

// uitextfield


    @IBOutlet var userID: UITextField!




    userID.resignFirstResponder()//resign keyboard focus





// global

        UIApplication.shared.sendAction(#selector(UIApplication.resignFirstResponder), to: nil, from: nil, for: nil);

블로그 이미지

엘로드넷

댓글을 달아 주세요


@IBOutlet var userID: UITextField!



    

    override func viewDidLoad() {

        super.viewDidLoad()


        // Do any additional setup after loading the view.

        

        userID.underlined()


        

    }





extension UITextField {

    

    func underlined(){

        let border = CALayer()

        let width = CGFloat(1.0)

        border.borderColor = UIColor.lightGray.cgColor

        border.frame = CGRect(x: 0, y: self.frame.size.height - width, width:  self.frame.size.width, height: self.frame.size.height)

        border.borderWidth = width

        self.layer.addSublayer(border)

        self.layer.masksToBounds = true

    }

}



블로그 이미지

엘로드넷

댓글을 달아 주세요

@IBOutlet var btnNext: UIButton!




self.btnNext.backgroundColor = hexStringToUIColor(hex:"#1994fc")




func hexStringToUIColor (hex:String) -> UIColor {

        var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()

        

        if (cString.hasPrefix("#")) {

            cString.remove(at: cString.startIndex)

        }

        

        if ((cString.characters.count) != 6) {

            return UIColor.gray

        }

        

        var rgbValue:UInt32 = 0

        Scanner(string: cString).scanHexInt32(&rgbValue)

        

        return UIColor(

            red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,

            green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,

            blue: CGFloat(rgbValue & 0x0000FF) / 255.0,

            alpha: CGFloat(1.0)

        )

    }




블로그 이미지

엘로드넷

댓글을 달아 주세요

텍스트 필드 변화 감지


    @IBOutlet var myPhoneNumber: UITextField!

    

  

    

    override func viewDidLoad() {

        super.viewDidLoad()


        // Do any additional setup after loading the view.

        



        myPhoneNumber.addTarget(self, action: #selector(textFieldDidChange(textField:)), for: .editingChanged)



    }




    func textFieldDidChange(textField: UITextField) {


    

        print(myPhoneNumber.text!)

        

    }

블로그 이미지

엘로드넷

댓글을 달아 주세요