Posts

How to get textsize - width - height UILabel and UITextView in ios swift (lấy độ dài - rộng nội dung của textview và label trong ios swift)

How to get textsize - width - height UILabel and UITextView in ios swift  func (hàm lấy textsize UILabel)      func  textSize(textlabel:  UILabel !) -> CGSize {          let  max_width: CGFloat ! =  self . frame . width          return  textlabel. attributedText !. boundingRectWithSize (                      CGSizeMake (max_width,  CGFloat .max),                                             options: [ NSStringDrawingOptions .UsesLineFragmentOrigin,                                                                 NSStringDrawingOptions ...

Animation View In Swift (Tạo hiệu ưng cho view trong swift - di chuyển)

Image
Hướng dẫn tạo hiệu ứng cho một đối tượng giao diện trong swift (Animation in swift) Tạo project Vào file Main.storyboard Các bạn tạo 2 đối tượng : Đối tượng UIIMageView: Hiển thị ảnh (Hoặc đối tượng bạn muốn tạo hiệu ứng) Đối tượng UIButton : Chúng ta sẽ di chuyển đối tượng ảnh khi click vào button                                           3. Kéo thả từng đối tượng vào file viewController.swift    Chúng ta có 2 đối tượng được khai báo như hình vẽ     Đối tượng button khai báo theo sự kiện                                       Trong func btnStart(sender:AnyObject) Sử dụng hàm UIView.animatedWithDuration  để tạo hiệu ứng di chuyển theo thời gian      @IBAction func btnStart(sender: ...

swift ios : sử dụng UIAlert - thông báo trong swift

Image
Hướng dẫn sử dụng UIAlert trong swift 1. Tạo project:  Hướng đẫn : http://swiftiosswift.blogspot.com/2016/03/swift-tao-project-au-tien-bang-xcode.html 2. vào file ViewController  Chúng ta bắt đầu viết code 2.1 Thông báo với 1 button   @IBAction func alert(sender: UIButton ) {                  let alertController = UIAlertController (title: "Thông báo" , message: "Bạn có tin nh ắ n mới" , preferredStyle: UIAlertControllerStyle . Alert )         let ok = UIAlertAction (title: "ok" , style: . Default , handler: { (action) -> Void in             print ( "ok" )                      })         alertController. addAction (ok)                  self . presentViewController (alertController, animated: true , completion: ...

Tải các phiên bản Xcode 6 / 7 đuôi .dmg

Image
Tải các phiên bản Xcode Xcode6/ 7  file dmg Link :  https://developer.apple.com/downloads/ Trước khi các bạn tải thì các bạn phải đăng nhập tài khoản trước 1. Xcode 7 : 7.3       download 7.2.1    download 7.2       download 7.1.1    download 7.1       download 7          download 2. Xcode 6: 6.4      download 6.3.2   download 6.3.1   download 6.3      download 6.2      download 6.0.1   download

Swift - ios Tạo bộ đếm ngược thời gian NSTimer

Image
Bài này mình sẽ hướng dẫn các bạn tạo bộ đếm ngược thời gian bằng các sử dụng hình ảnh. Trong các ứng dụng game thì bộ công cụ đếm ngược thời gian rất hay được sử dụng. vậy làm thế nào để tạo một bộ đếm thời gian. trong bài trước mình đã hướng dẫn các bạn sử dung đối tượng NSTimer.    1. Trước khi bắt đầu các bạn tải cho mình bộ ảnh thời gian đếm ngược ở đây nhé. 2. sau khi tải xong các bạn copy nó  vào project :                         Sau đó mở project lên : chuột phải vào thư mục project sao đó chọn  "add file to project" thư mục bạn vừa copy vào "                                        3.  Chúng ta bắt đầu tạo bộ đêm thời gian 3.1 Bài trước mình hd sử dụng kéo thả  . hôm này mình sẽ chỉnh sử dụng code để tạo giao diện cho bộ đếm. và file "viewcontroller" khai...

Swift : Customer Cell Tableview trong ios swift.

Image
Bài này mình sẽ hướng dẫn các bạn custom  tableViewCell trong code swift. 1. Như bào trước mình đã hướng dẫn các bạn tạo và hiển thị dữ liệu lên tableview ->  tạo và hiển thị dữ liệu trong tableview                                         2. Các bạn tạo cho mình 1 folder tên là customview Tiếp theo tạo 1 file tên là : tableViewCellExtension.swift chúng ta sẽ viết code lên file này  và có nội dung sau:  import Foundation import UIKit class tableViewCellExtension : UITableViewCell {          required init ?(coder aDecoder: NSCoder ) {         super . init (coder: aDecoder)     }       override init (style: UITableViewCellStyle , reuseIdentifier: String ?) {         super . init (style: style, reuseIdentifier: reuseIdentifier)   ...

Swift : sử dụng tableview trong swift - ios

Image
Bài này mình sẽ hướng dẫn các bạn tạo tableview và hiển thị dữ liệu trên tableview 1. Tạo project   -> sau đó đên file viewController 2. khai báo tableview : var table_view:UITableView ! vào hàm viewDidload : khởi tạo và tạo vị trí hiển thị - kích thước : table_view = UITableView () table_view . frame = CGRect (x: 0, y: 0, width: self . view . frame . width , height: -  self . view . frame . height ) self . view . addSubview ( table_view ) -> add table vào màn hình view 3. trong class ViewController ta kế thừa thêm các class :  class ViewController: UIViewController , UITableViewDelegate , UITableViewDataSource  {} Khai báo thêm các hàm protocol của  UITableViewDataSource           Hiển thị số dòng trên table mình fix cứng 10         -    func tableView(tableView: UITableView , numberOfRowsInSection section: Int ) -> Int {     ...

Swift ios - Các đối tượng giao diện cơ bản trong swift

Một số đối tượng cơ bản trong ngôn ngữ swift-ios 1. Đối tượng UILabel: Khai báo : var label:UILabel! = UILabel()   - >  Hiển thị text   - >  Một số thuộc tính của UILabel:         -  . text  : set giá trị text cho label            vd:  labe. text = "đây là label"         -  . textColor : set màu cho text  label            vd:  labe.  textColor = UIColor.redColor()         - . textAlignment : căn chỉnh trái - phải - giữa cho  text label            vd:  labe.  textAlignment = .center (căn giữa)         -  . frame : set vị trí cho Label            vd:  labe.  frame = CGRect(0,0,50,30)         -  . backgroundColor : set màu nền cho La...

Swift - ios Replace String - Thay thế ký tự trong chuỗi string

Image
Bài này mình hướng dẫn các bạn thay thế ký tự trong đoạn text string trong ios-swift khởi tạo : var  textString  :String = "chuỗi sẽ được thay thế 123456 chuỗi " Sủ dụng hàm :  textString . stringByReplacingOccurrencesOfString ( "old" , withString:   "new")        - VD: let  newtext  =  textString . stringByReplacingOccurrencesOfString ( "chuỗi" , withString:   "ok")           -> KQ:  " ok  sẽ được thay thế 123456  ok  "        -  let  newtext  =  textString . stringByReplacingOccurrencesOfString ( " thay thế " , withString:   "new")           -> KQ:  " ok  sẽ được  new  123456  ok  "        - let  newtext  =  textString . stringByReplacingOccurrencesOfString ( "chuỗi" , withString:   "ok")       ...