Search

stitchzaa

Some useful code & information for web dev (HTML5, CSS3, JavaScript) and iOS app dev (Swift)

Month

October 2015

Use regular expression to filter telephone number in JavaScript

function checkPhoneNumber(phone) {
    var regexp = /^(?:(?:\(?(?:00|\+)([1-4]\d\d|[1-9]\d?)\)?)?[\-\.\ \\\/]?)?((?:\(?\d{1,}\)?[\-\.\ \\\/]?){0,})(?:[\-\.\ \\\/]?(?:#|ext\.?|extension|x)[\-\.\ \\\/]?(\d+))?$/i
    if (regexp.test(phone) && phone.length > 0) {
        return true;
    } else {
        return false;
    }
}

Continue reading “Use regular expression to filter telephone number in JavaScript”

Import image from photo library into app in swift

Add  UIImagePickerControllerDelegate, UINavigationControllerDelegate  at top of the class.

 

Before viewDidLoad()

var picker = UIImagePickerController()

 

In viewDidLoad() or any function that you want to use image picker

picker.delegate = self

 

Add some function for catch event

// What to do when the picker returns with a photo
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    let chosenImage = info[UIImagePickerControllerEditedImage] as! UIImage
    dismissViewControllerAnimated(true, completion: nil)
    addAvatar(chosenImage)
//Use image that user pick from library
}

// What to do if the image picker cancels.
func imagePickerControllerDidCancel(picker: UIImagePickerController) {
    dismissViewControllerAnimated(true, completion: {() in
                // some code for do anything when user cancel to import image
    })
}

UIScrollView in Swift

Code for create UIScrollView (which named scrollView) and specify size of content (width and height) inside scrollView.

var scrollView = UIScrollView(frame: containerView.frame)

scrollView.contentSize = CGSize(width: 3000, height: 2000)

containerView.addSubview(scrollView)

// can be any view that is container of scrollView


Continue reading “UIScrollView in Swift”

Data-binding

Link of information about Data-binding Revolutions with Object.observe()

http://www.html5rocks.com/en/tutorials/es7/observe/

Material icons from Google

Material flat icons for web, Android, and iOS projects.

https://www.google.com/design/icons/

Blog at WordPress.com.

Up ↑