Thứ Năm, 23 tháng 5, 2019

WebView Android

- Layout:

 <WebView    
    android:id="@+id/webview"    
    android:layout_below="@+id/toolbar"    
    android:layout_width="match_parent"    
    android:layout_height="match_parent"/>

- Code main:

WebView myWebView = findViewById(R.id.webview);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.loadUrl(urlString);


- Add android:usesCleartextTraffic="true" to AndroidManifest.xml

<application    
    ...
    android:usesCleartextTraffic="true"
    ...
</application>

Thứ Tư, 8 tháng 5, 2019

UITableView Swift

class MenuScreenVC: UIViewController, UITableViewDataSource, UITableViewDelegate {
    
    @IBOutlet weak var tableView: UITableView!
    var listMenu: [OptionItemDTO] = []

    override func viewDidLoad() {
        super.viewDidLoad()
        
        initDataMenu()
        
        self.tableView.tableFooterView = UIView()
        self.tableView.delegate = self
        self.tableView.dataSource = self
        self.tableView.register(UINib(nibName: "MenuViewCell", bundle: Bundle.main), forCellReuseIdentifier: "MenuViewCell")
    }
    
    // tableview
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return self.listMenu.count
    }
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        return 64
    }
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        
        let cell = tableView.dequeueReusableCell(withIdentifier: "MenuViewCell") as! MenuViewCell
        let dto = listMenu[indexPath.row]
        cell.binđata(dto: dto)
        return cell
    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        let cell:MenuViewCell = tableView.cellForRow(at:indexPath) as! MenuViewCell
        let vc = WebViewVC()
        vc.urlString = cell.dto?.url ?? ""
        self.navigationController?.pushViewController(vc, animated: true)

    }
}

SpickerView Swift



import UIKit

class TimePopupVC: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
    
    @IBOutlet weak var viewContent: UIView!
    @IBOutlet weak var pickerTime: UIPickerView!
    
    var delegate: AddCalendarVCProtocol?
    var listTime: [TimeSlotDTO] = []
    var listTimeValue: [String] = []
    var selectedIndex: Int = 0

    override func viewDidLoad() {
        super.viewDidLoad()

        // Do any additional setup after loading the view.
        for item in listTime {
            listTimeValue.append(item.getValue())
        }
        self.pickerTime.delegate = self
        self.pickerTime.dataSource = self
    }
    
    @IBAction func btnOKTapped(_ sender: Any) {
        delegate?.setTime(selectedIndex)
        self.dismiss(animated: true, completion: nil)
    }
    
    
    // Number of columns of data
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }
    
    // The number of rows of data
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return listTimeValue.count
    }
    
    // The data to return fopr the row and component (column) that's being passed in
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return listTimeValue[row]
    }
    
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
        selectedIndex = row
    }
}


Thứ Bảy, 4 tháng 5, 2019

Đổi màu status bar ios sang màu trắng

1. Thêm View controller-based status bar appearance trong file in Info.plist

2. Chọn Status Bar Style thành Light:

enter image description here