最近在研究Xamarin.Forms,發現如果要將Picker Control的文字置中或置右的話...,需要使用CustomRender再搭配條件式編譯的方式(假設要放在Share library裡)。

#if __IOS__

        using UIKit;
        using Xamarin.Forms.Platform.iOS;

#elif __ANDROID__

        using Xamarin.Forms.Platform.Android;
        using Android.Views;

#endif

[assembly: ExportRenderer(typeof(Picker), typeof(CustomPickerRenderer))]
namespace MilitaryCountdown
{
        public class CustomPickerRenderer : PickerRenderer
        {
                protected override void OnElementChanged(ElementChangedEventArgs e)
                {
                        base.OnElementChanged(e);

                        if (Control != null)
                        {
#if __IOS__
                                Control.TextAlignment = UITextAlignment.Center;
#elif __ANDROID__
                                Control.Gravity = GravityFlags.CenterHorizontal;
#endif
                        }
                }

        }
}

 

小賢 發表在 痞客邦 留言(0) 人氣()

 

import UIKit
import AVFoundation

extension Date {
    func toString(format: String) -> String {
        let dateFormat = DateFormatter()
        dateFormat.dateFormat = format
        
        return dateFormat.string(from: self)
    }
}

class ViewController: UIViewController {
    
    @IBOutlet weak var textView: UITextView!
    
    let synth = AVSpeechSynthesizer()
    var timer = Timer()
    
    @IBAction func startHandler(_ sender: UIButton) {
        
        timer.invalidate()
        timer = Timer.scheduledTimer(withTimeInterval: 5, repeats: true) { [weak self] (timer) in
            
            guard let weakSelf = self else {
                return
            }
            
            let text = "現在時刻:" + Date().toString(format: "HH:mm")
            weakSelf.textView.text = text
            
            let myUtterance = AVSpeechUtterance(string: text)
            myUtterance.voice = AVSpeechSynthesisVoice(language: "zh-TW")
            myUtterance.rate = 0.5
            weakSelf.synth.speak(myUtterance)
        }
        
        timer.fire()
    }
    
    @IBAction func endHandler(_ sender: UIButton) {
        timer.invalidate()
        synth.stopSpeaking(at: .word)
    }
}

 

小賢 發表在 痞客邦 留言(0) 人氣()

    通常在Run專案的時候,可能會有些修改(例如: 還原以前砍掉的某個功能...),如果以前的commit的東西,有用最小單位來commit的話.. ,這樣可以很輕鬆的使用SourceTree的Reverse commit,來還原某筆的commit (他會建立一個完全相反的commit,新增變刪除、刪除變新增)。

小賢 發表在 痞客邦 留言(0) 人氣()

    主要受到下面兩個很神的Github repository的影響,嘗試自己做一個類似C# async await功能

https://github.com/yannickl/AwaitKit

小賢 發表在 痞客邦 留言(0) 人氣()

    Swift的Promise,可以把非同步的Code用then then then串接下去(解決Callback hell),試用了一下還蠻讚的,跟javascript的一樣好用@@

 

小賢 發表在 痞客邦 留言(0) 人氣()